예제 #1
0
 public function testSetWith()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->assert('Set the asserter with something else than an object throw an exception')->exception(function () use(&$line, $asserter, &$value) {
         $line = __LINE__;
         $asserter->setWith($value = rand(-PHP_INT_MAX, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not an object'), $asserter->getTypeOf($value)))->integer($asserter->getValue())->isEqualTo($value)->variable($asserter->getCharlist())->isNull()->assert('The asserter was returned when it set with an object')->object($asserter->setWith($object = new \exception()))->isIdenticalTo($asserter)->string($asserter->getValue())->isEqualTo((string) $object)->variable($asserter->getCharlist())->isNull()->assert('It is possible to define a character list')->object($asserter->setWith($object = new \exception(), null, $charlist = ""))->isIdenticalTo($asserter)->string($asserter->getValue())->isEqualTo((string) $object)->string($asserter->getCharlist())->isEqualTo($charlist);
 }
예제 #2
0
 public function testSetWith()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->assert('Set the asserter with something else than a boolean throw an exception')->exception(function () use(&$line, $asserter, &$value) {
         $line = __LINE__;
         $asserter->setWith($value = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not a boolean'), $asserter->getTypeOf($value)))->assert('The asserter was returned when it set with a boolean')->string($asserter->getValue())->isEqualTo($value)->object($asserter->setWith(true))->isIdenticalTo($asserter)->boolean($asserter->getValue())->isTrue();
 }
예제 #3
0
 public function testSetWith()
 {
     $this->if($object = new TestedClass($generator = new asserter\generator()))->and($value = uniqid())->then->exception(function () use($object, $value) {
         $object->setWith($value);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not an object'), $object->getAnalyzer()->getTypeOf($value)))->if($value = new \StdClass())->then->exception(function () use($object, $value) {
         $object->setWith($value);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not a crawler'), $object->getAnalyzer()->getTypeOf($value)))->if($crawler = new \mock\Symfony\Component\DomCrawler\Crawler())->then->object($object->setWith($crawler))->isIdenticalTo($object);
 }
예제 #4
0
 public function testHasLength()
 {
     $this->if($asserter = new asserters\utf8String($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->hasLength(rand(0, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Value is undefined')->if($asserter->setWith(''))->and($diff = new diffs\variable())->then->exception(function () use($asserter, &$requiredLength) {
         $asserter->hasLength($requiredLength = rand(1, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('length of %s is not %d'), $asserter->getTypeOf(''), $requiredLength))->object($asserter->hasLength(0))->isIdenticalTo($asserter)->if($asserter->setWith($string = $this->getRandomUtf8String()))->then->object($asserter->hasLength(mb_strlen($string, 'UTF-8')))->isIdenticalTo($asserter);
 }
예제 #5
0
파일: object.php 프로젝트: ronan-gloo/atoum
 public function testIsCloneOf()
 {
     $this->if($asserter = new asserters\object($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->isCloneOf($asserter);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Object is undefined')->if($asserter->setWith($asserter))->then->exception(function () use($asserter) {
         $asserter->isCloneOf($asserter);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not a clone of %s'), $asserter, $asserter))->if($clonedAsserter = clone $asserter)->then->object($asserter->isCloneOf($clonedAsserter))->isIdenticalTo($asserter);
 }
예제 #6
0
파일: hash.php 프로젝트: ronan-gloo/atoum
 public function testIsMd5()
 {
     $this->if($asserter = new asserters\hash($generator = new asserter\generator()))->and($asserter->setWith($value = hash('md5', 'hello')))->then->object($asserter->isMd5())->isIdenticalTo($asserter)->if($asserter->setWith($value = strtoupper($value)))->then->object($asserter->isMd5())->isIdenticalTo($asserter)->if($asserter->setWith($newvalue = substr($value, 1)))->and($diff = new diffs\variable())->and($diff->setReference($newvalue)->setData($value))->then->exception(function () use($asserter, &$line) {
         $line = __LINE__;
         $asserter->isMd5();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($this->getLocale()->_('%s should be a string of %d characters'), $asserter, strlen($value)))->if($asserter->setWith($newvalue = 'z' . substr($value, 1)))->and($diff = new diffs\variable())->and($diff->setReference($newvalue)->setData($value))->then->exception(function () use($asserter, &$line) {
         $line = __LINE__;
         $asserter->isMd5();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s does not match given pattern'), $asserter));
 }
예제 #7
0
 public function testSetWith()
 {
     $this->if($asserter = new asserters\afterDestructionOf($generator = new asserter\generator()))->and($value = uniqid())->then->exception(function () use(&$line, $asserter, $value) {
         $line = __LINE__;
         $asserter->setWith($value);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not an object'), $asserter->getTypeOf($value)))->object($asserter->setWith($objectWithDestructor = new \mock\mageekguy\atoum\tests\units\asserters\classWithDestructor()))->isIdenticalTo($asserter)->mock($objectWithDestructor)->call('__destruct')->once()->if($objectWithoutDestructor = new classWithoutDestructor())->then->exception(function () use(&$otherLine, $asserter, $objectWithoutDestructor) {
         $otherLine = __LINE__;
         $asserter->setWith($objectWithoutDestructor);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Destructor of class %s is undefined'), get_class($objectWithoutDestructor)));
 }
예제 #8
0
 /**
  * @dataProvider dataProviderNearlyEqualTo
  */
 public function testIsNearlyEqualTo($value, $testValue, $epsilon, $pass)
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->and($asserter->setWith($value));
     if ($pass) {
         $this->object($asserter->isNearlyEqualTo($testValue, $epsilon))->isIdenticalTo($asserter);
     } else {
         $this->if($diff = new diffs\variable())->and($diff->setExpected($testValue)->setActual($value))->then->exception(function () use($asserter, $testValue, $epsilon) {
             $asserter->isNearlyEqualTo($testValue, $epsilon);
         })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not nearly equal to %s with epsilon %s'), $asserter, $asserter->getTypeOf($testValue), $epsilon) . PHP_EOL . $diff);
     }
 }
예제 #9
0
파일: stream.php 프로젝트: ronan-gloo/atoum
 public function testIsWrited()
 {
     $this->if($asserter = new asserters\stream($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->isWrited();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Stream is undefined')->if($streamController = atoum\mock\stream::get($streamName = uniqid()))->and($streamController->file_put_contents = strlen($contents = uniqid()))->and($asserter->setWith($streamName))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->isWrited();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($failMessage = sprintf($generator->getLocale()->_('stream %s is not writed'), $streamName))->when(function () use($streamName, $contents) {
         file_put_contents('atoum://' . $streamName, $contents);
     })->object($asserter->isWrited())->isIdenticalTo($asserter);
 }
예제 #10
0
 public function testHasNestedException()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter) {
         $asserter->hasNestedException();
     })->isInstanceOf('logicException')->hasMessage('Exception is undefined')->if($asserter->setWith(new atoum\exceptions\runtime('', 0)))->then->exception(function () use($asserter) {
         $asserter->hasNestedException();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('exception does not contain any nested exception'))->exception(function () use($asserter) {
         $asserter->hasNestedException(new \exception());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('exception does not contain this nested exception'))->if($asserter->setWith(new atoum\exceptions\runtime('', 0, $nestedException = new \exception())))->then->object($asserter->hasNestedException())->isIdenticalTo($asserter)->object($asserter->hasNestedException($nestedException))->isIdenticalTo($asserter)->exception(function () use($asserter) {
         $asserter->hasNestedException(new \exception());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('exception does not contain this nested exception'));
 }
예제 #11
0
파일: object.php 프로젝트: xihewang/atoum
 public function testIsEmpty()
 {
     $this->if($asserter = $this->newTestedInstance($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->isEmpty();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Object is undefined')->exception(function () use($asserter) {
         $asserter->isEmpty;
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Object is undefined')->if($asserter->setWith($this))->then->exception(function () use($asserter) {
         $asserter->isEmpty();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s has size %d'), $asserter, sizeof($this)))->exception(function () use($asserter, &$failMessage) {
         $asserter->isEmpty($failMessage = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($failMessage)->exception(function () use($asserter) {
         $asserter->isEmpty;
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s has size %d'), $asserter, sizeof($this)))->if($asserter->setWith(new \arrayIterator()))->then->object($asserter->isEmpty())->isIdenticalTo($asserter)->object($asserter->isEmpty)->isIdenticalTo($asserter);
 }
예제 #12
0
파일: error.php 프로젝트: ronan-gloo/atoum
 public function testExists()
 {
     $this->if($asserter = new asserters\error($generator = new asserter\generator()))->then->exception(function () use(&$line, $asserter) {
         $asserter->exists();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('error does not exist'))->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(0, PHP_INT_MAX), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty()->if($asserter->setWith($message = uniqid(), null))->then->exception(function () use(&$line, $asserter) {
         $asserter->exists();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('error with message \'%s\' does not exist'), $message))->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(0, PHP_INT_MAX), $message, uniqid(), rand(1, PHP_INT_MAX)))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty()->if($asserter->setWith($message = uniqid(), $type = E_USER_ERROR))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->exists();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('error of type %s with message \'%s\' does not exist'), asserters\error::getAsString($type), $message))->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type, $message, uniqid(), rand(1, PHP_INT_MAX)))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty()->if($asserter->setWith(null, $type = E_USER_ERROR))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->exists();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('error of type %s does not exist'), asserters\error::getAsString($type)))->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type, uniqid(), uniqid(), rand(1, PHP_INT_MAX)))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty()->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(1, PHP_INT_MAX), $message = uniqid() . 'FOO' . uniqid(), uniqid(), rand(1, PHP_INT_MAX)))->and($asserter->withPattern('/FOO/')->withType(null))->then->object($asserter->exists())->isIdenticalTo($asserter)->array($asserter->getScore()->getErrors())->isEmpty();
 }
예제 #13
0
 public function testHasLengthLessThan()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->hasLengthLessThan(rand(0, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Value is undefined')->if($asserter->setWith('Chuck Norris'))->and($diff = new diffs\variable())->then->exception(function () use($asserter, &$requiredLength) {
         $asserter->hasLengthLessThan($requiredLength = 10);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('length of %s is not less than %d'), $asserter->getTypeOf('Chuck Norris'), $requiredLength))->object($asserter->hasLengthLessThan(20))->isIdenticalTo($asserter)->if($asserter->setWith($string = uniqid()))->then->object($asserter->hasLengthLessThan(strlen($string) + 1))->isIdenticalTo($asserter);
 }
예제 #14
0
 public function getAsserterClass($asserter)
 {
     $asserterLower = strtolower($asserter);
     if (in_array($asserterLower, array('testedClass', 'mock', 'adapter', 'phpFunction'))) {
         return null;
     }
     return parent::getAsserterClass($asserter);
 }
예제 #15
0
 public function testHasDateAndTime()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->hasDateAndTime(1981, 2, 13, 1, 2, 3);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Instance of \\dateTime is undefined')->if($asserter->setWith($dateTime = new \DateTime('1981-02-13 01:02:03')))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->hasDateAndTime(1900, 1, 1, 4, 5, 6);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Datetime is %s instead of %s'), '1981-02-13 01:02:03', '1900-01-01 04:05:06'))->object($asserter->hasDateAndTime('1981', '02', '13', '01', '02', '03'))->isIdenticalTo($asserter)->object($asserter->hasDateAndTime('1981', '2', '13', '1', '2', '3'))->isIdenticalTo($asserter)->object($asserter->hasDateAndTime(1981, 2, 13, 1, 2, 3))->isIdenticalTo($asserter);
 }
예제 #16
0
 public function testHasKeys()
 {
     $this->if($asserter = new asserters\phpArray($generator = new asserter\generator()))->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter) {
         $asserter->hasSize(rand(0, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Array is undefined')->if($asserter->setWith(array()))->then->exception(function () use($asserter) {
         $asserter->hasKeys(array(0));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s should have keys %s'), $asserter, $asserter->getTypeOf(array(0))))->if($asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid())))->then->exception(function () use($asserter) {
         $asserter->hasKeys(array(0, 'first', 2, 'second'));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s should have keys %s'), $asserter, $asserter->getTypeOf(array('first', 'second'))))->object($asserter->hasKeys(array(0, 2, 4)))->isIdenticalTo($asserter);
 }
예제 #17
0
 public function test__construct()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->object($asserter->getLocale())->isIdenticalTo($generator->getLocale())->object($asserter->getGenerator())->isIdenticalTo($generator)->variable($asserter->getValue())->isNull()->boolean($asserter->wasSet())->isFalse();
 }
예제 #18
0
 public function testIsNotTrue()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter) {
         $asserter->isNotNull(rand(-PHP_INT_MAX, PHP_INT_MAX));
     })->isInstanceOf('logicException')->hasMessage('Value is undefined')->if($asserter->setWith(uniqid()))->then->object($asserter->isNotTrue())->isIdenticalTo($asserter)->if($asserter->setWith(true))->then->exception(function () use($asserter) {
         $asserter->isNotTrue();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is true'), $asserter));
 }
예제 #19
0
 public function testSetWith()
 {
     $this->if($asserter = new asserters\mysqlDateTime($generator = new asserter\generator()))->then->exception(function () use($asserter, &$value) {
         $asserter->setWith($value = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not in format Y-m-d H:i:s'), $asserter->getTypeOf($value)))->string($asserter->getValue())->isEqualTo($value)->object($asserter->setWith($value = '1976-10-06 14:05:54'))->isIdenticalTo($asserter)->string($asserter->getValue())->isIdenticalTo($value)->object($asserter->setWith($value = uniqid(), false))->isIdenticalTo($asserter)->string($asserter->getValue())->isEqualTo($value);
 }
 /**
  * @param Response           $response
  * @param asserter\generator $asserter
  * @param string             $expectedResponseContentType application/json|application/xml
  */
 private function checkForHttpError(Response $response, asserter\generator $asserter, $expectedResponseContentType)
 {
     if ($response->isError() || $this->isHttpErrorFatal($response, $expectedResponseContentType)) {
         $asserter->boolean(true)->isTrue('Benchmarking encountered a Fatal Error');
     }
 }
예제 #21
0
 public function testGetAsserterClass()
 {
     $this->if($generator = new testedClass())->and($generator->setAdapter($adapter = new atoum\test\adapter()))->and($adapter->class_exists = true)->then->string($generator->getAsserterClass($asserter = uniqid()))->isEqualTo('mageekguy\\atoum\\asserters\\' . $asserter)->string($generator->getAsserterClass('\\' . $asserter))->isEqualTo('\\' . $asserter)->if($generator->setAlias($alias = uniqid(), $asserter))->then->string($generator->getAsserterClass($asserter))->isEqualTo(testedClass::defaultAsserterNamespace . '\\' . $asserter)->string($generator->getAsserterClass($alias))->isEqualTo(testedClass::defaultAsserterNamespace . '\\' . $asserter)->if($generator->setAsserterNamespace($namespace = uniqid()))->then->string($generator->getAsserterClass($asserter))->isEqualTo($namespace . '\\' . $asserter)->string($generator->getAsserterClass($alias))->isEqualTo($namespace . '\\' . $asserter)->if($adapter->class_exists = false)->variable($generator->getAsserterClass($asserter))->isNull();
 }
예제 #22
0
 public function testIsLessThanOrEqualTo()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->and($asserter->setWith($value = -rand(1, PHP_INT_MAX - 1)))->then->object($asserter->isLessThanOrEqualTo(0))->isIdenticalTo($asserter)->object($asserter->isLessThanOrEqualTo($value))->isIdenticalTo($asserter)->if($diff = new diffs\variable())->and($diff->setExpected(-PHP_INT_MAX)->setActual($value))->then->exception(function () use($asserter, $value) {
         $asserter->isLessThanOrEqualTo(-PHP_INT_MAX);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not less than or equal to %s'), $asserter, $asserter->getTypeOf(-PHP_INT_MAX)));
 }
예제 #23
0
 public function test__construct()
 {
     $this->if($asserter = new sut())->then->object($asserter->getGenerator())->isEqualTo(new asserter\generator())->object($asserter->getLocale())->isIdenticalTo($asserter->getGenerator()->getLocale())->string($asserter->getValue())->isEmpty()->boolean($asserter->wasSet())->isTrue()->if($asserter = new sut($generator = new asserter\generator()))->then->object($asserter->getGenerator())->isIdenticalTo($generator)->object($asserter->getLocale())->isIdenticalTo($generator->getLocale())->string($asserter->getValue())->isEmpty()->boolean($asserter->wasSet())->isTrue();
 }
예제 #24
0
 public function testHasMethod()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->hasMethod(uniqid());
     })->isInstanceOf('logicException')->hasMessage('Class is undefined')->if($class = uniqid())->and($method = uniqid())->and($reflectionClass = new \mock\reflectionClass($class = uniqid()))->and($reflectionClassController = $reflectionClass->getMockController())->and($reflectionClassController->getName = $class)->and($reflectionClassController->hasMethod = false)->and($asserter->setReflectionClassInjector(function ($class) use($reflectionClass) {
         return $reflectionClass;
     })->setWith($class))->then->exception(function () use($asserter, $method) {
         $asserter->hasMethod($method);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Method %s::%s() does not exist'), $class, $method))->if($reflectionClassController->hasMethod = true)->then->object($asserter->hasMethod(uniqid()))->isIdenticalTo($asserter);
 }
예제 #25
0
 public function testSetGenerator()
 {
     $this->if($asserter = new sut(new atoum\asserter\generator()))->then->object($asserter->setGenerator($generator = new atoum\asserter\generator()))->isIdenticalTo($asserter)->object($asserter->getGenerator())->isIdenticalTo($generator)->object($asserter->getLocale())->isIdenticalTo($generator->getLocale())->object($asserter->setGenerator())->isIdenticalTo($asserter)->object($asserter->getGenerator())->isNotIdenticalTo($generator)->isEqualTo(new atoum\asserter\generator());
 }
예제 #26
0
 public function getAsserterInstance($asserter, array $arguments = array())
 {
     return parent::getAsserterInstance($asserter, $arguments)->setWithTest($this->test);
 }
예제 #27
0
 public function test__construct()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->object($asserter->getLocale())->isIdenticalTo($generator->getLocale())->object($asserter->getGenerator())->isIdenticalTo($generator)->object($asserter->getAdapter())->isEqualTo(new atoum\adapter())->variable($asserter->getName())->isNull();
 }
예제 #28
0
 public function testIsNotIdenticalTo()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->isNotIdenticalTo(new \mock\object());
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Array is undefined')->if($asserter->setWith($array = array(1, 2)))->then->object($asserter->isNotIdenticalTo(array('1', 2)))->isIdenticalTo($asserter)->exception(function () use($asserter, $array) {
         $asserter->isNotIdenticalTo($array);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is identical to %s'), $asserter, $asserter->getTypeOf($array)))->if($asserter->integer)->then->object($asserter->isNotIdenticalTo(array('1', 2)))->isIdenticalTo($asserter)->if($asserter->integer[1])->then->object($asserter->isEqualTo(2))->isIdenticalTo($asserter)->object($asserter->isEqualTo(2)->isNotEqualTo(5))->isIdenticalTo($asserter)->if($diff = new diffs\variable())->then->exception(function () use($asserter, &$expectedValue) {
         $asserter->isEqualTo($expectedValue = rand(3, PHP_INT_MAX));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is not equal to %s'), $asserter->getTypeOf($asserter->getInnerValue()), $asserter->getTypeOf($expectedValue)) . PHP_EOL . $diff->setExpected($expectedValue)->setActual(2));
 }
예제 #29
0
 public function testEnd()
 {
     $this->given($document = new \DOMDocument())->if($generator = new asserter\generator())->and($parent = new CrawlerAssert($generator))->and($object = new TestedClass($generator, $parent))->and($crawler = new \mock\Symfony\Component\DomCrawler\Crawler())->and($this->calling($crawler)->count = 0)->and($object->setWith($crawler))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected at least %d element(s) matching %s, found %d.'), 1, '*', 0))->if($this->calling($crawler)->count = 1)->then->object($object->end())->isIdenticalTo($parent)->if($object->atLeast(2))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected at least %d element(s) matching %s, found %d.'), 2, '*', 1))->if($this->calling($crawler)->count = 3)->then->object($object->end())->isIdenticalTo($parent)->if($object->atMost(2))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected at most %d element(s) matching %s, found %d.'), 2, '*', 3))->if($object->exactly(2))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected %d element(s) matching %s, found %d.'), 2, '*', 3))->if($this->calling($crawler)->count = 2)->then->object($object->end())->isIdenticalTo($parent)->if($generator = new asserter\generator())->and($parent = new CrawlerAssert($generator))->and($object = new TestedClass($generator, $parent))->and($elem = $document->createElement(uniqid('_')))->and($otherElem = $document->createElement(uniqid('_')))->and($crawler = new \Symfony\Component\DomCrawler\Crawler(array($elem, $otherElem)))->and($object->setWith($crawler))->and($object->withAttribute($attr = uniqid('_'), $value = uniqid()))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected at least %d element(s) matching %s, found %d.'), 1, '*[' . $attr . '="' . $value . '"]', 0))->if($elem->setAttribute($attr, $value))->then->object($object->end())->isIdenticalTo($parent)->if($object->exactly(2))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected %d element(s) matching %s, found %d.'), 2, '*[' . $attr . '="' . $value . '"]', 1))->if($object->withContent($content = uniqid()))->then->exception(function () use($object) {
         $object->end();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Expected %d element(s) matching %s, found %d.'), 2, '*[' . $attr . '="' . $value . '"][@content="' . $content . '"]', 0));
 }
예제 #30
0
 public function testNever()
 {
     $this->if($asserter = new asserters\adapter($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Adapter is undefined')->if($asserter->setWith($adapter = new test\adapter()))->then->exception(function () use($asserter) {
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Called function is undefined')->if($call = new php\call('md5'))->and($asserter->call('md5'))->then->object($asserter->never())->isIdenticalTo($asserter)->if($adapter->md5($usedArg = uniqid()))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)))->if($adapter->resetCalls())->and($asserter->withArguments($arg = uniqid()))->then->object($asserter->never())->isIdenticalTo($asserter)->if($adapter->md5($arg))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg)))->if($adapter->md5($arg))->then->exception(function () use(&$otherLine, $asserter) {
         $otherLine = __LINE__;
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('function %s is called 2 times instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg)))->if($asserter->withArguments(uniqid()))->then->object($asserter->never())->isIdenticalTo($asserter);
 }