unset($fooFilter); unset($barFilter); unset($bazFilter); // @Test: ->getFilters() $fc = new Sonata_FilterChain(); $t->ok(is_array($fc->getFilters()) && count($fc->getFilters()) == 0, 'The method returns the empty filters array'); // @Test: ->addFilter() $fc = new Sonata_FilterChain(); $fc->addFilter($fooFilter); $fc->addFilter($barFilter); $fc->addFilter($bazFilter); $t->is($fc->getFilters(), array($fooFilter, $barFilter, $bazFilter), 'All filters were added correctly'); // @Test: ->processFilters() $request = new Sonata_Request(); $response = new Sonata_Response(); $fooFilter = $t->mock('FooFilter'); $fooFilter->execute($request, $response)->once(); $fooFilter->replay(); $barFilter = $t->mock('BarFilter'); $barFilter->execute($request, $response)->once(); $barFilter->replay(); $bazFilter = $t->mock('BazFilter'); $bazFilter->execute($request, $response)->once(); $bazFilter->replay(); $fc = new Sonata_FilterChain(); $fc->addFilter($fooFilter); $fc->addFilter($barFilter); $fc->addFilter($bazFilter); $fc->processFilters($request, $response); $fooFilter->verify(); // @Test: Countable Interface
/* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ LimeAnnotationSupport::enable(); $t = new LimeTest(); // @Before $executable = new LimeExecutable(LimeExecutable::php() . ' %file%'); $file = tempnam(sys_get_temp_dir(), 'lime'); $output = $t->mock('LimeOutputInterface'); $input = new LimeInputTap($output); // @After $file = null; $output = null; $input = null; // @Test: Successful tests are passed to pass() // fixtures $output->pass('A passed test', '', 0, '', ''); $output->replay(); // test $input->parse("ok 1 - A passed test\n"); // assertions $t->ok($input->done(), 'The input is done'); // @Test: Successful tests without message are passed to pass() // fixtures
{ return $this->preFilterChainMock; } protected function initializePostFilterChain() { return $this->postFilterChainMock; } } $fh = fopen(dirname(__FILE__) . '/../fixtures/controllers/ArticleController.class.php', 'wb'); fputs($fh, '<?php class ArticleController extends Sonata_Controller_Action {} ?>'); fclose($fh); $fh = fopen(dirname(__FILE__) . '/../fixtures/controllers/InvalidController.class.php', 'wb'); fputs($fh, '<?php class InvalidController {} ?>'); fclose($fh); // @Before $requestMock = $t->mock('Sonata_Request'); $responseMock = $t->mock('Sonata_Response'); $routeMapMock = $t->mock('Sonata_RouteMap'); $templateViewMock = $t->mock('Sonata_TemplateView'); $preFilterChainMock = $t->mock('Sonata_FilterChain'); $postFilterChainMock = $t->mock('Sonata_FilterChain'); $containerMock = $t->mock('sfServiceContainerInterface'); $containerMock->getService('request')->returns($requestMock); $containerMock->getService('response')->returns($responseMock); $containerMock->getService('route_map')->returns($routeMapMock); $containerMock->getService('template_view')->returns($templateViewMock); $containerMock->replay(); $dispatcher = new DispatcherHelper($containerMock, $preFilterChainMock, $postFilterChainMock); // @After unset($requestMock); unset($responseMock);
{ return $this->varHolderMock; } public function fooAction() { } public function barAction() { return self::ACTION_FAILURE; } public function myBar() { } } // @Before $requestMock = $t->mock('Sonata_Request'); $responseMock = $t->mock('Sonata_Response'); $varHolderMock = $t->mock('Sonata_ParameterHolder'); $templateVewMock = $t->mock('Sonata_TemplateView'); $fooController = new FooController($requestMock, $responseMock, $varHolderMock); // @After unset($requestMock); unset($responseMock); unset($varHolderMock); unset($templateVewMock); // @Test: ->dispatch() // @Test: general try { $fooController->dispatch('fail', $templateVewMock); $t->fail('No code should be executed after calling non-existing actions'); } catch (Sonata_Exception_Controller_Action $ex) {
public function tearDown() { $this->impl->tearDown(); } public function testDoSomething() { $this->impl->testDoSomething(); } public function testDoSomethingElse() { $this->impl->testDoSomethingElse(); } } $t = new LimeTest(); // @Before $output = $t->mock('LimeOutputInterface', array('nice' => true)); $configuration = $t->stub('LimeConfiguration'); $configuration->getTestOutput()->returns($output); $configuration->replay(); $test = new TestCase($configuration); $output->reset(); $test->impl = $t->mock('Test'); // @Test: The methods setUp() and tearDown() are called before and after each test method // fixtures $test->impl->setUp(); $test->impl->testDoSomething(); $test->impl->tearDown(); $test->impl->setUp(); $test->impl->testDoSomethingElse(); $test->impl->tearDown(); $test->impl->replay();
return array('config' => dirname(__FILE__) . '/../config', 'controllers' => dirname(__FILE__) . '/../controllers', 'templates' => dirname(__FILE__) . '/../templates'); } public function registerRoutes(Sonata_RouteMap $map) { } public function registerPreFilters() { return array(); } public function registerPostFilters() { return array(); } } // @Before $containerMock = $t->mock('sfContainerInterface'); $dispatcherMock = $t->mock('Sonata_Dispatcher'); $app = new SonataAppHelper($containerMock); $app->setDispatcherMock($dispatcherMock); // @After unset($containerMock); unset($dispatcherMock); unset($preFilterChainMock); unset($postFilterChainMock); unset($app); // @Test: ->run() $requestMock = $t->mock('Sonata_Reqeust'); $responseMock = $t->mock('Sonata_Response'); $routeMapMock = $t->mock('Sonata_RouteMap'); $templateViewMock = $t->mock('Sonata_TemplateView'); $containerMock->getService('request')->returns($requestMock)->once();
<?php /* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ LimeAnnotationSupport::enable(); $t = new LimeTest(); // @Before $printer = $t->mock('LimePrinter', array('strict' => true)); $configuration = $t->stub('LimeConfiguration'); $configuration->replay(); $output = new LimeOutputTap($printer, $configuration); // @After $printer = null; $output = null; // @Test: focus() prints the filename $printer->printLine('# /test/file', LimePrinter::INFO); $printer->replay(); // test $output->focus('/test/file'); // @Test: focus() prints the filename only once $printer->printLine('# /test/file', LimePrinter::INFO)->once(); $printer->replay(); // test $output->focus('/test/file');
<?php /* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ $t = new LimeTest(); $t->diag('The before callbacks are called before each test method'); // fixtures $mock = $t->mock('Mock', array('strict' => true)); $r = new LimeTestRunner(); $r->addBefore(array($mock, 'setUp')); $r->addTest(array($mock, 'testDoSomething'), 'Do something', '/test/file', 11); $r->addTest(array($mock, 'testDoSomethingElse'), 'Do something else', '/test/file', 22); $mock->setUp('Do something', '/test/file', 11); $mock->testDoSomething(); $mock->setUp('Do something else', '/test/file', 22); $mock->testDoSomethingElse(); $mock->replay(); // test $r->run(); $t->diag('The after callbacks are called before each test method'); // fixtures $mock = $t->mock('Mock', array('strict' => true)); $r = new LimeTestRunner(); $r->addAfter(array($mock, 'tearDown'));
* * @author Pascal Cremer <*****@*****.**> */ require_once dirname(__FILE__) . '/bootstrap.php'; $t = new LimeTest(); // @BeforeAll class TestFilter extends Sonata_Filter { public function execute(Sonata_Request $request, Sonata_Response $response) { } } class TestFilterDecorator extends Sonata_Filter_Decorator { public function doExecute(Sonata_Request $request, Sonata_Response $response) { } } // @Before $request = new Sonata_Request(); $response = new Sonata_Response(); // @After unset($request); unset($response); // @Test: ->execute() $filter = $t->mock('TestFilter'); $filter->execute($request, $response)->once(); $filter->replay(); $filterDecorator = new TestFilterDecorator($filter); $filterDecorator->execute($request, $response); $filter->verify();