Beispiel #1
0
 public function testWrite()
 {
     $this->if($adapter = new atoum\test\adapter())->if($adapter->fopen = function () {
         trigger_error(uniqid());
         return false;
     })->and($file = new testedClass(null, $adapter))->and($adapter->resetCalls())->then->exception(function () use($file) {
         $file->write(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to open file \'' . $file->getFilename() . '\'')->error->notExists()->if($adapter->fopen = $resource = uniqid())->and($adapter->flock = false)->and($adapter->resetCalls())->then->exception(function () use($file) {
         $file->write(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to lock file \'' . $file->getFilename() . '\'')->if($file = new testedClass(null, $adapter))->and($adapter->flock = true)->and($adapter->ftruncate = true)->and($adapter->fclose = function () {
     })->and($adapter->fwrite = false)->and($adapter->fflush = function () {
     })->and($adapter->resetCalls())->then->exception(function () use($file) {
         $file->write(uniqid());
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to write in file \'' . $file->getFilename() . '\'')->adapter($adapter)->call('fopen')->withArguments($file->getFilename(), 'c')->once()->call('flock')->withArguments($resource, LOCK_EX)->once()->if($adapter->fwrite = function ($resource, $data) {
         return strlen($data);
     })->and($file = new testedClass(null, $adapter))->and($adapter->resetCalls())->then->object($file->write($string = uniqid()))->isIdenticalTo($file)->adapter($adapter)->call('fopen')->withArguments($file->getFilename(), 'c')->once()->call('flock')->withArguments($resource, LOCK_EX)->once()->call('fwrite')->withArguments($resource, $string)->once()->call('fflush')->withArguments($resource)->once()->object($file->write($string = uniqid() . "\n"))->isIdenticalTo($file)->adapter($adapter)->call('fwrite')->withArguments($resource, $string)->after($this->adapter($adapter)->call('fopen')->withArguments($file->getFilename(), 'c'))->after($this->adapter($adapter)->call('flock')->withArguments($resource, LOCK_EX))->before($this->adapter($adapter)->call('fflush')->withArguments($resource))->once();
 }
Beispiel #2
0
 public function testSetFilename()
 {
     $this->if($handle = uniqid())->and($adapter = new atoum\test\adapter())->and($adapter->fopen = function () use($handle) {
         return $handle;
     })->and($adapter->fclose = function () {
     })->and($adapter->fwrite = function () {
     })->and($adapter->is_writable = function () {
         return true;
     })->and($adapter->is_null = function () {
         return true;
     })->and($file = new writers\file(null, $adapter))->then->string($file->getFilename())->isEqualTo('atoum.log')->if($file->setFilename('anotherName'))->then->string($file->getFilename())->isEqualTo('anotherName')->if($adapter->is_null = function () {
         return false;
     })->and($obj = $file->write($string = uniqid()))->and($file->setFilename('anotherNameAgain'))->then->string($file->getFilename())->isEqualTo('anotherName');
 }