Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/NinjaMutex/AbstractTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Kamil Dziedzic  >  Ninja Mutex  >  tests/NinjaMutex/AbstractTest.php  >  Download  
File: tests/NinjaMutex/AbstractTest.php
Role: Unit test script
Content type: text/plain
Description: Test
Class: Ninja Mutex
Lock resources to prevent simultaneous accesses
Author: By
Last change:
Date: 2013-09-15 08:36
Size: 2,394 bytes
 

Contents

Class file image Download
<?php
/**
 * This file is part of ninja-mutex.
 *
 * (C) Kamil Dziedzic <arvenil@klecza.pl>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace NinjaMutex;

use 
Memcache;
use 
Memcached;
use 
NinjaMutex\Lock\FlockLock;
use 
NinjaMutex\Lock\MemcacheLock;
use 
NinjaMutex\Lock\MemcachedLock;
use 
NinjaMutex\Lock\MySqlLock;
use 
NinjaMutex\Mock\MockMemcache;
use 
NinjaMutex\Mock\MockMemcached;
use 
NinjaMutex\Mock\MockPDO;
use 
NinjaMutex\Mock\MockPredisClient;
use 
NinjaMutex\Lock\PredisRedisLock;
use 
Predis;
use 
org\bovigo\vfs;

abstract class 
AbstractTest extends \PHPUnit_Framework_TestCase
{
    public function 
setUp()
    {
        
vfs\vfsStreamWrapper::register();
        
vfs\vfsStreamWrapper::setRoot(new vfs\vfsStreamDirectory('nfs'));
        
mkdir('/tmp/mutex/');
    }

    public function 
tearDown()
    {
        foreach (new \
DirectoryIterator(vfs\vfsStream::url('nfs')) as $file) {
            if (!
$file->isDot()) {
                
unlink($file->getPathname());
            }
        }
        
rmdir(vfs\vfsStream::url('nfs'));

        foreach (new \
DirectoryIterator('/tmp/mutex/') as $file) {
            if (!
$file->isDot()) {
                
unlink($file->getPathname());
            }
        }
        
rmdir('/tmp/mutex/');
    }

    public function 
lockImplementorProvider()
    {
        
// Just mocks
        
$memcacheMock = new MockMemcache();
        
$memcachedMock = new MockMemcached();
        
$data = array();
        
$data[] = array(new FlockLock(vfs\vfsStream::url('nfs/')));
        
$data[] = array(new MemcacheLock($memcacheMock));
        
$data[] = array(new MemcachedLock($memcachedMock));
        
$data[] = array(new MySqlLock('''''''NinjaMutex\Mock\MockPDO'));
        
$data[] = array(new PredisRedisLock(new MockPredisClient()));

        
// Real interfaces
        
$memcache = new Memcache();
        
$memcache->connect('127.0.0.1'11211);
        
$memcached = new Memcached();
        
$memcached->addServer('127.0.0.1'11211);
        
$data[] = array(new FlockLock('/tmp/mutex/'));
        
$data[] = array(new MemcachedLock($memcached));
        
$data[] = array(new MemcacheLock($memcache));
        
$data[] = array(new MySqlLock('root''''127.0.0.1'));
        
$data[] = array(new PredisRedisLock(new Predis\Client()));

        return 
$data;
    }
}