Beispiel #1
0
<?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();
// @BeforeAll
$file1 = $t->stub('LimeFile');
$file1->getPath()->returns('test1.txt');
$file1->replay();
$file2 = $t->stub('LimeFile');
$file2->getPath()->returns('test2.txt');
$file2->replay();
$file3 = $t->stub('LimeFile');
$file3->getPath()->returns('test3.txt');
$file3->replay();
// @Before
$label1 = new LimeLabel();
$label1->addFile($file1);
$label1->addFile($file2);
$label2 = new LimeLabel();
$label2->addFile($file1);
$label2->addFile($file3);
// @Test: intersect() returns the intersection of two labels
Beispiel #2
0
    {
        $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();
// test
Beispiel #3
0
<?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
$colorizer = $t->stub('LimeColorizer');
$printer = new LimePrinter($colorizer);
// @After
$colorizer = null;
$printer = null;
// @Test: printText() prints text using the given style
// fixtures
$colorizer->colorize('My text', 'RED')->returns('<RED>My text</RED>');
$colorizer->replay();
// test
ob_start();
$printer->printText('My text', 'RED');
$result = ob_get_clean();
// assertions
$t->is($result, '<RED>My text</RED>', 'The result was colorized and printed');
// @Test: printLine() prints text followed by a newline
// fixtures
$cp = new Sonata_Parser_Config(new MyParserDriver());
// @After
unlink($configFile);
unset($cp);
// @Test: ->getDriver()
$t->is($cp->getDriver() instanceof MyParserDriver, true, 'The driver was returned correctly');
// @Test: ->setDriver()
$cp->setDriver(new MyOtherParserDriver());
$t->is($cp->getDriver() instanceof MyOtherParserDriver, true, 'The new driver was set correctly');
// @Test: ->parse()
try {
    $cp->parse('some_non_existing_file.yml');
    $t->fail('No code should be executed after this');
} catch (RuntimeException $ex) {
    $t->pass('An exception is thrown if the config file cannot be found');
}
$driverStub = $t->stub('MyParserDriver');
$driverStub->doParse($configFile)->throws('InvalidArgumentException');
$driverStub->replay();
$cp->setDriver($driverStub);
try {
    $cp->parse($configFile);
    $t->fail('No code should be executed after this');
} catch (InvalidArgumentException $ex) {
    $t->pass('An exception thrown by the driver will also be thrown by the config parser');
}
$driverStub = $t->stub('MyParserDriver');
$driverStub->doParse($configFile)->returns(array("foo" => array("bar" => 42, "baz" => 4711)));
$driverStub->replay();
$cp->setDriver($driverStub);
$t->is($cp->parse($configFile), array("foo" => array("bar" => 42, "baz" => 4711)), 'Returns an array with all parsed values');
<?php

/**
 * This file is part of the Sonata RESTful PHP framework
 * (c) 2009-2010 Pascal Cremer <*****@*****.**>
 *
 * @author Pascal Cremer <*****@*****.**>
 */
require_once dirname(__FILE__) . '/bootstrap.php';
$t = new LimeTest();
// @Before
$requestStub = $t->stub('Sonata_Request');
$rm = new Sonata_RouteMap($requestStub);
// @After
unset($requestMock);
unset($rm);
// @Test: ->connect()
// @Test: trying '/foo/bar'
$rm->connect('/foo/bar', 'foo', array(), 'bar');
$routes = $rm->getRoutes();
$t->is(count($routes), 1, 'The route was connected (added) to the routes array');
$route = array_pop($routes);
$t->ok($route instanceof Sonata_Route, 'The added route is a PSRoute object');
$t->is($route->getPattern(), '/^\\/foo\\/bar/', 'The pattern has the right form further regex operations');
$t->is($route->getResource(), 'foo', 'The resource was set correctly');
$t->is($route->getVerbs(), array(), 'There were no verbs to set');
$t->is($route->getAction(), 'bar', 'The action was set correctly');
$t->is($route->getParameters(), array(), 'There were no parameters to set');
$t->is($route->getCommandName(), 'BarFoo', 'The camelized command name is generated correctly');
// @Test: trying '/my_foo/my_bar'
$rm->connect('/my_foo/my_bar', 'my_foo', array(), 'my_bar');
Beispiel #6
0
<?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->getVerbose()->returns(false);
$configuration->getProcesses()->returns(1);
$configuration->replay();
$output = new LimeOutputSuite($printer, $configuration);
// @After
$printer = null;
$output = null;
// @Test: When close() is called, the test summary is printed
// fixtures
$printer->printText(str_pad('script', 73, '.'));
$printer->printLine("ok", LimePrinter::OK);
$printer->replay();
// test
$output->focus('/test/script');
$output->pass('A passed test', 'Class', 100, '/test/script', 11);