Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/NinjaMutex/Lock/LockTest.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/Lock/LockTest.php  >  Download  
File: tests/NinjaMutex/Lock/LockTest.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: 10 months ago
Size: 3,869 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\Lock;

use 
NinjaMutex\AbstractTest;

/**
 * Tests for Locks
 *
 * @author Kamil Dziedzic <arvenil@klecza.pl>
 */
class LockTest extends AbstractTest
{
    
/**
     * @dataProvider lockImplementorProvider
     * @param LockInterface $lockImplementor
     */
    
public function testDisallowToAcquireSelfOwnedLock(LockInterface $lockImplementor)
    {
        
$name 'forfiter';
        
$lockImplementor->acquireLock($name0);

        
$this->assertFalse($lockImplementor->acquireLock($name0));

        
$lockImplementor->releaseLock($name);
    }

    
/**
     * @dataProvider lockImplementorProvider
     * @param LockInterface $lockImplementor
     */
    
public function testDisallowToAcquireLockOwnedByOtherLockImplementor(LockInterface $lockImplementor)
    {
        
$name 'forfiter';
        
$duplicateLockImplementor = clone $lockImplementor;
        
$lockImplementor->acquireLock($name0);

        
$this->assertFalse($duplicateLockImplementor->acquireLock($name0));

        
$lockImplementor->releaseLock($name);
    }

    
/**
     * @dataProvider lockImplementorProvider
     * @param LockInterface $lockImplementor
     */
    
public function testDisallowLockImplementorToReleaseLockAcquiredByOtherImplementor(LockInterface $lockImplementor)
    {
        
$name 'forfiter';
        
$lockImplementor->acquireLock($name0);

        
$duplicateLockImplementor = clone $lockImplementor;
        
$this->assertFalse($duplicateLockImplementor->releaseLock($name));

        
$lockImplementor->releaseLock($name);
    }

    
/**
     * @dataProvider lockImplementorProvider
     * @param LockInterface $lockImplementor
     */
    
public function testIfLocksAreNotSharedBetweenImplementors(LockInterface $lockImplementor)
    {
        
$name 'forfiter';
        
$lockImplementor->acquireLock($name0);

        
$duplicateLockImplementor = clone $lockImplementor;
        
$duplicateLockImplementor->releaseLock($name);
        
$this->assertFalse($duplicateLockImplementor->acquireLock($name0));

        
$lockImplementor->releaseLock($name);
    }

    
/**
     * @dataProvider lockImplementorProvider
     * @param LockInterface $lockImplementor
     */
    
public function testIfLockReleasedByOneImplementorCanBeAcquiredByOther(LockInterface $lockImplementor)
    {
        
$name 'forfiter';
        
$lockImplementor->acquireLock($name0);
        
$lockImplementor->releaseLock($name);

        
$duplicateLockImplementor = clone $lockImplementor;
        
$this->assertTrue($duplicateLockImplementor->acquireLock($name0));

        
$duplicateLockImplementor->releaseLock($name);
    }

    
/**
     * @dataProvider lockImplementorProvider
     * @param LockInterface $lockImplementor
     */
    
public function testAcquireAndReleaseLock(LockInterface $lockImplementor)
    {
        
$name 'forfiter';
        
$this->assertTrue($lockImplementor->acquireLock($name0));
        
$this->assertTrue($lockImplementor->isLocked($name));
        
$this->assertTrue($lockImplementor->releaseLock($name));
        
$this->assertFalse($lockImplementor->isLocked($name));
    }

    
/**
     * @dataProvider lockImplementorProvider
     * @param LockInterface $lockImplementor
     */
    
public function testIfLockIsReleasedAfterLockImplementorIsDestroyed(LockInterface $lockImplementor)
    {
        
$name 'forfiter';
        
$duplicateLockImplementor = clone $lockImplementor;
        
$duplicateLockImplementor->acquireLock($name0);
        unset(
$duplicateLockImplementor);

        
$this->assertTrue($lockImplementor->acquireLock($name0));

        
$lockImplementor->releaseLock($name);
    }
}