fail() 공개 정적인 메소드

Failed assertion
public static fail ( $message, $actual = NULL, $expected = NULL ) : void
리턴 void
예제 #1
0
 public function __construct(array $params, DBAL\Driver $driver, DBAL\Configuration $config = NULL, Common\EventManager $eventManager = NULL)
 {
     $container = \Testbench\ContainerFactory::create(FALSE);
     $this->onConnect[] = function (DoctrineConnectionMock $connection) use($container) {
         if ($this->__testbench_databaseName !== NULL) {
             //already initialized (needed for pgsql)
             return;
         }
         try {
             $config = $container->parameters['testbench'];
             if ($config['shareDatabase'] === TRUE) {
                 $registry = new \Testbench\DatabasesRegistry();
                 $dbName = $container->parameters['testbench']['dbprefix'] . getenv(\Tester\Environment::THREAD);
                 if ($registry->registerDatabase($dbName)) {
                     $this->__testbench_database_setup($connection, $container, TRUE);
                 } else {
                     $this->__testbench_databaseName = $dbName;
                     $this->__testbench_database_change($connection, $container);
                 }
             } else {
                 // always create new test database
                 $this->__testbench_database_setup($connection, $container);
             }
         } catch (\Exception $e) {
             \Tester\Assert::fail($e->getMessage());
         }
     };
     parent::__construct($params, $driver, $config, $eventManager);
 }
예제 #2
0
 /**
  * @param array $configs
  * @return Nette\DI\Container
  */
 protected function createContainer(array $configs = [])
 {
     $sl = $this->parentCreateContainer($configs);
     /** @var DbConnectionMock $db */
     $db = $sl->getByType('Doctrine\\DBAL\\Connection');
     if (!$db instanceof DbConnectionMock) {
         $serviceNames = $sl->findByType('Doctrine\\DBAL\\Connection');
         throw new \LogicException(sprintf('The service %s should be instance of Kdyby\\TesterExtras\\DbConnectionMock, to allow lazy schema initialization', reset($serviceNames)));
     }
     $db->onConnect[] = function (Connection $db) use($sl) {
         if ($this->databaseName !== NULL) {
             return;
         }
         try {
             if (!method_exists($this, 'doSetupDatabase')) {
                 throw new \LogicException(sprintf("Method %s:%s is not implemented", get_class($this), __FUNCTION__));
             }
             $this->doSetupDatabase($db);
         } catch (\Exception $e) {
             Tracy\Debugger::log($e, Tracy\Debugger::ERROR);
             Assert::fail($e->getMessage());
         }
     };
     return $sl;
 }
예제 #3
0
파일: Match.php 프로젝트: redhead/mockyll
 public static function notNull()
 {
     return static::match(function ($arg) {
         if ($arg === NULL) {
             Assert::fail('%1 should not be null', $arg);
         }
     });
 }
예제 #4
0
 public static function close()
 {
     foreach (self::$expected as $functionName => $expectedArgs) {
         if (!isset(self::$called[$functionName])) {
             Assert::fail("Function '{$functionName}' was expected, but not called");
         }
     }
 }
예제 #5
0
 /**
  * @internal
  * @return \Nette\DI\Container
  */
 private function __testbench_ndb_getContainer()
 {
     if ($this->__testbench_ndb_container === NULL) {
         $container = \Testbench\ContainerFactory::create(FALSE);
         /** @var Connection $db */
         $db = $container->getByType('Nette\\Database\\Connection');
         $db->onConnect[] = function (Connection $db) use($container) {
             if ($this->__testbench_ndb_databaseName !== NULL) {
                 return;
             }
             try {
                 $this->__testbench_ndb_setupDatabase($db, $container);
             } catch (\Exception $e) {
                 \Tester\Assert::fail($e->getMessage());
             }
         };
         $this->__testbench_ndb_container = $container;
     }
     return $this->__testbench_ndb_container;
 }
예제 #6
0
 protected function createContainer()
 {
     $container = $this->parentCreateContainer();
     /** @var ConnectionMock $db */
     $db = $container->getByType(Connection::class);
     if (!$db instanceof ConnectionMock) {
         throw new \LogicException("Connection service should be instance of ConnectionMock");
     }
     $db->onConnect[] = function (Connection $db) use($container) {
         if ($this->databaseName !== NULL) {
             return;
         }
         try {
             $this->setupDatabase($db);
         } catch (\Exception $e) {
             Tester\Assert::fail($e->getMessage());
         }
     };
     return $container;
 }
예제 #7
0
 /** @internal */
 private function __testbench_createContainer()
 {
     if (!class_exists('Doctrine\\DBAL\\Connection')) {
         \Tester\Environment::skip('TDoctrine trait supports only Doctrine at this moment.');
     }
     $container = \Testbench\ContainerFactory::create(FALSE);
     /** @var ConnectionMock $db */
     $db = $container->getByType('Doctrine\\DBAL\\Connection');
     if (!$db instanceof ConnectionMock) {
         $serviceNames = $container->findByType('Doctrine\\DBAL\\Connection');
         throw new \LogicException(sprintf('The service %s should be instance of Ant\\Tests\\ConnectionMock, to allow lazy schema initialization.', reset($serviceNames)));
     }
     $db->onConnect[] = function (ConnectionMock $db) use($container) {
         if ($this->__testbench_databaseName !== NULL) {
             return;
         }
         try {
             $this->setupDatabase($db, $container);
         } catch (\Exception $e) {
             \Tester\Assert::fail($e->getMessage());
         }
     };
     return $container;
 }
예제 #8
0
 /**
  * Assert array equality without considering key order and with strict comparision
  *
  * In numeric-indexed arrays, keys are considered insignificant, ie. array(1, 2, 3) and array(3, 2, 1) are equal in terms of this assertion.
  * In associative arrays, keys are significant, however order of items in array is not.
  *
  * Items are compared using strict operator ===
  *
  * @param array $expected
  * @param array $actual
  */
 static function arraySame($expected, $actual)
 {
     if (!self::isArraySame($expected, $actual)) {
         NAssert::fail('%1 should be same (without considering key order) to %2', $actual, $expected);
     }
 }
예제 #9
0
 /**
  * @param string $destination
  * @param string $formName
  * @param array $post
  * @param string|boolean $path Path after redirect or FALSE if it's form without redirect
  *
  * @return \Nette\Application\Responses\RedirectResponse
  * @throws \Tester\AssertException
  */
 protected function checkForm($destination, $formName, $post = [], $path = '/')
 {
     if (is_string($path)) {
         return $this->checkRedirect($destination, $path, ['do' => $formName . '-submit'], $post);
     } elseif (is_bool($path)) {
         /** @var \Nette\Application\Responses\RedirectResponse $response */
         $response = $this->check($destination, ['do' => $formName . '-submit'], $post);
         if (!$this->__testbench_exception) {
             Assert::same(200, $this->getReturnCode());
             Assert::type('Nette\\Application\\Responses\\TextResponse', $response);
         }
         return $response;
     } else {
         \Tester\Assert::fail('Path should be string or boolean (probably FALSE).');
     }
 }
 private function dropTempDatabase()
 {
     try {
         $ret = $this->query("DROP DATABASE IF EXISTS {$this->tempDatabaseName}");
         if ($ret === false) {
             throw new \RuntimeException("query() method returned false.");
         }
     } catch (\Exception $e) {
         Assert::fail("Could not delete temporary database \"{$this->tempDatabaseName}\" - you might want to delete it manually.");
         return null;
     }
     $this->databaseExists = false;
 }
예제 #11
0
 /**
  * @Given /^kliknu na (tlačítko|odkaz) (.+)$/
  */
 public function clickButton($type, $text)
 {
     $text = trim($text);
     switch ($type) {
         case 'tlačítko':
             $buttons = $this->getSession()->elements($this->getSession()->using('xpath')->value("//input[@type='submit'][@value='{$text}']"));
             if (!$buttons) {
                 $buttons = $this->getSession()->elements($this->getSession()->using('xpath')->value("//button[@type='submit'][./text()[contains(.,'{$text}')]]"));
             }
             break;
         case 'odkaz':
             $buttons = $this->getSession()->elements($this->getSession()->using('partial link text')->value($text));
             break;
     }
     if ($button = reset($buttons)) {
         /** @var Element $button */
         $button->click();
     } else {
         Assert::fail("Button with title '{$text}' was not found");
     }
     if (!($className = $this->seleniumContext->findPageObjectClass())) {
         throw new \RuntimeException("Router didn't match the url " . $this->getSession()->url());
     }
     if (!$this->getCurrentPage() instanceof $className) {
         $this->pushPage(new $className($this->getSession()));
     }
     $this->getSession()->waitForAjax();
 }
 private function testInvalid()
 {
     $file = $this->sniffer->processFile(Tester::$setup['validDir'] . $this->testedFile->getName() . '.php');
     $errors = $file->getErrors();
     foreach ($this->expectedOnLines as $line) {
         $errorsOnLine = isset($errors[$line]) ? $errors[$line] : [];
         $errorFound = FALSE;
         foreach ($errorsOnLine as $error) {
             if ($error[0]['message'] === $this->expectedMessage) {
                 $errorFound = TRUE;
                 break;
             }
         }
         if ($errorFound) {
             Assert::fail('Message "' . $this->expectedMessage . '" found on line "' . $line . '" but was not expected.');
         }
     }
 }
예제 #13
0
 /**
  * @eventListener onInvalidAnnotation
  * @param  NonExistingClass $invalid
  * @throws \Tester\AssertException
  */
 public function onInvalidAnnotation($invalid)
 {
     unset($invalid);
     Assert::fail('Invalid annotation passed.');
 }
예제 #14
0
파일: DomAssert.php 프로젝트: venne/tester
 /**
  * @param $expected
  * @param $selector
  * @param $attribute
  * @return $this
  */
 public function xpathContainsAttribute($expected, $selector, $attribute)
 {
     if (!($el = $this->getObject()->xpath($selector))) {
         Assert::fail("Selector '{$selector}' does not exist.");
     }
     $attrs = (array) $el[0]->attributes();
     $attrs = $attrs['@attributes'];
     if (!isset($attrs[$attribute])) {
         Assert::fail("Attribute '{$attribute}' does not exist.");
     }
     Assert::equal($expected, $attrs[$attribute]);
     return $this;
 }