Example #1
1
 private function assessOutputMatch(Job $job, $content)
 {
     if (!Tester\Assert::isMatching($content, $job->getOutput())) {
         Dumper::saveOutput($job->getFile(), $job->getOutput(), '.actual');
         Dumper::saveOutput($job->getFile(), $content, '.expected');
         return array(Runner::FAILED, 'Failed: output should match ' . Dumper::toLine(rtrim($content)));
     }
 }
Example #2
0
 /**
  * @param  string                $presenterName is fully qualified presenter name (module:module:presenter)
  * @param  string                $action
  * @param  string                $method
  * @param  array                 $params
  * @param  array                 $post
  * @return Application\IResponse
  */
 public function assertFormSubmitted($presenterName, $action, $method = 'GET', $params = array(), $post = array())
 {
     $presenter = $this->createPresenter($presenterName);
     $res = $this->processRequest($presenter, $presenterName, $action, $method, $params, $post);
     Assert::type('Nette\\Application\\Responses\\RedirectResponse', $res);
     return $res;
 }
Example #3
0
function routeIn(Nette\Application\IRouter $route, $url, $expectedPresenter = NULL, $expectedParams = NULL, $expectedUrl = NULL, $scriptPath = NULL)
{
    $url = new Nette\Http\UrlScript("http://example.com{$url}");
    if ($scriptPath) {
        $url->setScriptPath($scriptPath);
    }
    if ($url->getQueryParameter('presenter') === NULL) {
        $url->setQueryParameter('presenter', 'querypresenter');
    }
    $url->appendQuery(['test' => 'testvalue']);
    $httpRequest = new Nette\Http\Request($url);
    $request = $route->match($httpRequest);
    if ($request) {
        // matched
        $params = $request->getParameters();
        asort($params);
        asort($expectedParams);
        Assert::same($expectedPresenter, $request->getPresenterName());
        Assert::same($expectedParams, $params);
        $result = $route->constructUrl($request, $url);
        Assert::same($expectedUrl, $result);
    } else {
        // not matched
        Assert::null($expectedPresenter);
    }
}
Example #4
0
 public function __construct($abc, $xyz, $false, $null)
 {
     \Tester\Assert::same('test', $abc);
     \Tester\Assert::same(159753, $xyz);
     \Tester\Assert::same(FALSE, $false);
     \Tester\Assert::null($null);
 }
Example #5
0
 /**
  * @eventListener onFoo
  * @param int $one
  * @param int $two
  * @param int $three
  */
 public function onFoo($one, $two, $three)
 {
     Assert::equal(1, $one);
     Assert::equal(2, $two);
     Assert::equal(3, $three);
     $this->called = TRUE;
 }
function _register_wrapper($namespace)
{
    $fs = new FileSystem(new Connector(new ConnectorConfig(), new PathTranslator($namespace)));
    Assert::true(Wrapper::register($fs));
    $context = stream_context_create(array('dir' => array('recursive' => true)));
    @rmdir('redis://', $context);
}
Example #7
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;
 }
 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);
 }
Example #9
0
 public function testDelete()
 {
     $req = Request::create($this->baseDomain . '/test/1', Methods::DELETE);
     $app = new App(NULL, $req);
     $app->attach($this->router);
     $app->run();
     \Tester\Assert::equal('DELETE 1', $this->callResult);
 }
Example #10
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");
         }
     }
 }
Example #11
0
 public static function assertTypeError($function)
 {
     if (PHP_VERSION_ID < 70000) {
         Assert::error($function, E_RECOVERABLE_ERROR);
     } else {
         Assert::exception($function, '\\TypeError');
     }
 }
 /**
  * @param IComparable $five
  * @param IComparable $six
  */
 public function assertForComparison(IComparable $five, IComparable $six)
 {
     Assert::true($five->isLessThan($six));
     Assert::true($five->isLessThanOrEqual($six));
     Assert::false($six->isLessThan($five));
     Assert::false($six->isLessThanOrEqual($five));
     Assert::false($five->isEqual($six));
     Assert::false($six->isEqual($five));
 }
Example #13
0
 function testExport()
 {
     Helper::$presenter->forceAjaxMode = FALSE;
     $params = $this->params + array('do' => 'grid-export-export');
     ob_start();
     Helper::request($params)->send(mock('\\Nette\\Http\\IRequest'), new \Nette\Http\Response());
     $output = ob_get_clean();
     Assert::same(file_get_contents(__DIR__ . "/files/export.expect"), $output);
 }
Example #14
0
 /**
  * @param string $expectedJson
  * @param string $input
  */
 public static function json($expectedJson, $input)
 {
     $decodedExpectedJson = self::jsonDecode($expectedJson, 'Expected-json');
     $decodedInput = self::jsonDecode($input, 'Input-json');
     try {
         Assert::equal($decodedExpectedJson, $decodedInput);
     } catch (AssertException $e) {
         throw new AssertException('%1 should be equal to %2', self::makeJsonPretty($expectedJson), self::makeJsonPretty($input));
     }
 }
Example #15
0
 private function assertLimit(IDataSource $source)
 {
     $all = $source->fetchAll();
     Assert::count(self::LIMIT, $all);
     Assert::count(self::FULL_USER_COUNT, $source->fetchFullData());
     Assert::count(self::FULL_USER_COUNT, $source->fetchAllForExport());
     Assert::same(self::FULL_USER_COUNT, $source->getTotalCount());
     Assert::same(self::LIMIT, $source->count());
     return $all;
 }
Example #16
0
 /**
  * @param $destination
  * @param array $args
  */
 protected function assertDestination($destination, $args = array())
 {
     $appRequest = $this->seleniumContext->getSession()->presenter();
     Assert::true(empty($appRequest));
     Assert::same($destination, $appRequest->getPresenterName());
     foreach ($args as $param => $value) {
         Assert::true(array_key_exists($param, $appRequest->parameters));
         Assert::same($value, $appRequest->parameters[$param]);
     }
 }
Example #17
0
 function testExport()
 {
     Helper::$presenter->forceAjaxMode = FALSE;
     $params = $this->params + array('do' => 'grid-export-export');
     ob_start();
     Helper::request($params)->send(mock('\\Nette\\Http\\IRequest'), new \Nette\Http\Response());
     $output = ob_get_clean();
     //@todo - resolve this wtf? different sorting (dibi, nette db, doctrine) vs (array source)
     $type = in_array(get_called_class(), array('Grido\\Tests\\ArraySourceTest')) ? '.array' : '';
     Assert::same(file_get_contents(__DIR__ . "/files/export{$type}.expect"), $output);
 }
 public function testCallback()
 {
     $form = new Form();
     $sug = $form->addSuggestion('suggestion')->setCallback(array($this, 'suggestionCallback'));
     $this->assertSame(array('query1', 'query2'), $sug->call('query'));
     A::throws(function () use($sug) {
         $sug->getControl();
     }, 'Nette\\InvalidStateException');
     $this->assertInstanceOf('Nette\\Utils\\Html', $sug->getControl(FALSE));
     $sug->setLink('link');
     $this->assertInstanceOf('Nette\\Utils\\Html', $sug->getControl());
 }
Example #19
0
 public function testFetchLastRawRows()
 {
     $source = $this->createArraySourceWithDataStructure();
     Assert::exception(function () use($source) {
         $source->fetchLastRawRows();
     }, InvalidStateException::class);
     $source->fetchAll();
     $rawData = $source->fetchLastRawRows();
     Assert::count(self::FULL_USER_COUNT, $rawData);
     foreach ($rawData as $item) {
         Assert::type(ArrayHash::class, $item);
     }
 }
Example #20
0
 protected function checkRenderOutput(IComponent $control, $expected, array $renderParameters = [])
 {
     if (!$control->getParent()) {
         $this->attachToPresenter($control);
     }
     ob_start();
     $control->render(...$renderParameters);
     if (is_file($expected)) {
         \Tester\Assert::matchFile($expected, ob_get_clean());
     } else {
         \Tester\Assert::match($expected, ob_get_clean());
     }
 }
Example #21
0
 public function testBasicFunctionality()
 {
     $inputData = ['courier' => ['name' => 'Nikola Tesla'], 'checkpoints' => [['type' => 'source', 'arrivalExpected' => '2014-10-16 19:00:00 +0200', 'arrivalReal' => '2014-10-16 19:00:00 +0200', 'departureReal' => NULL, 'estimatedDelay' => 0], ['type' => 'destination', 'arrivalExpected' => NULL, 'arrivalReal' => NULL, 'departureReal' => NULL, 'estimatedDelay' => 0]], 'isWarrantyClaim' => TRUE, 'orderId' => 12345678];
     $orderTimesDTO = new OrderTimesDTO($inputData);
     Assert::same('Nikola Tesla', $orderTimesDTO->getCourierName());
     Assert::equal(new \DateTime('2014-10-16 19:00:00 +0200'), $orderTimesDTO->getSourceCheckpoint()['arrivalExpected']);
     Assert::equal(new \DateTime('2014-10-16 19:00:00 +0200'), $orderTimesDTO->getSourceCheckpoint()['arrivalReal']);
     Assert::same(NULL, $orderTimesDTO->getSourceCheckpoint()['departureReal']);
     Assert::same(0, $orderTimesDTO->getSourceCheckpoint()['estimatedDelay']);
     Assert::same(NULL, $orderTimesDTO->getDestinationCheckpoint()['arrivalExpected']);
     Assert::same(NULL, $orderTimesDTO->getDestinationCheckpoint()['arrivalReal']);
     Assert::same(NULL, $orderTimesDTO->getDestinationCheckpoint()['departureReal']);
     Assert::same(0, $orderTimesDTO->getDestinationCheckpoint()['estimatedDelay']);
     Assert::same(TRUE, $orderTimesDTO->isIsWarrantyClaim());
 }
 public function testMask()
 {
     $form = new Form();
     $mask = $form->addMask('mask');
     $mask->setMask('999 *** aaa');
     $mask->getControl();
     $rules = $mask->getRules()->getIterator();
     $this->assertSame('[0-9][0-9][0-9] [0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z] [a-zA-Z][a-zA-Z][a-zA-Z]', $rules[0]->arg);
     A::throws(function () use($mask) {
         $mask->setMask('999');
     }, 'Exception');
     A::throws(function () use($mask) {
         $mask->setRegex('999');
     }, 'Exception');
 }
Example #23
0
 public function testExportFiltered()
 {
     $data = $this->data;
     $callback = function ($source) use($data) {
         Assert::same($data, $source);
     };
     $export = $this->grid->addExportCallback('Export', $callback, TRUE);
     $this->grid->addFilterText('name', 'Name');
     $grid = $this->grid;
     $trigger = function () use($grid) {
         $this->grid->handleExport(1);
     };
     Assert::exception($trigger, 'Ublaboo\\DataGrid\\Exception\\DataGridException', 'You have to set a data source first.');
     $this->grid->setDataSource($this->data);
     $this->grid->handleExport(1);
 }
Example #24
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;
 }
 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;
 }
Example #26
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;
 }
Example #27
0
 protected static function matchCounts(IFilterSource $source, $filteredCount, $fullCount, $rawClassType)
 {
     static $lastRowsDescription = 'Output from fetchLastRawRows after %s';
     $users = $source->fetchAll();
     if (count($users) > 0) {
         Assert::type(ArrayHash::class, reset($users));
     }
     Assert::count($filteredCount, $users, 'Output from fetchAll');
     $lastRows = $source->fetchLastRawRows();
     if (count($lastRows) > 0) {
         Assert::type($rawClassType, reset($lastRows));
     }
     Assert::count($filteredCount, $lastRows, sprintf($lastRowsDescription, 'fetchAll'));
     $fullData = $source->fetchFullData();
     if (count($fullData) > 0) {
         Assert::type(ArrayHash::class, reset($fullData));
     }
     Assert::count($fullCount, $fullData, 'Output from fetchFullData');
     $lastRows = $source->fetchLastRawRows();
     if (count($lastRows) > 0) {
         Assert::type($rawClassType, reset($lastRows));
     }
     Assert::count($fullCount, $lastRows, sprintf($lastRowsDescription, 'fetchFullData'));
 }
Example #28
0
 /**
  * @return $this
  */
 public function valid()
 {
     Assert::true($this->getObject()->isValid());
     return $this;
 }
 protected function assertBuilder($expected, QueryBuilder $builder)
 {
     $args = $builder->getQueryParameters();
     array_unshift($args, $builder->getQuerySql());
     Assert::same($expected, $args);
 }
Example #30
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);
     }
 }