本文整理汇总了PHP中LimeTest::expect方法的典型用法代码示例。如果您正苦于以下问题:PHP LimeTest::expect方法的具体用法?PHP LimeTest::expect怎么用?PHP LimeTest::expect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LimeTest
的用法示例。
在下文中一共展示了LimeTest::expect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dirname
<?php
/*
* This file is part of the Lime framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
require_once dirname(__FILE__) . '/setup.php';
LimeAnnotationSupport::enable();
$t = new LimeTest();
// @Test
$t->expect('RuntimeException');
echo "Test 1\n";
throw new RuntimeException();
// @Test
$t->expect('LogicException');
echo "Test 2\n";
// should not result in "Got: RuntimeException"!
示例2: LimeTest
* This file is part of the Lime framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
*
* 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();
// @Test: is() throws an exception if keys are missing
// fixtures
$actual = new LimeTesterArray(array());
$expected = new LimeTesterArray(array(0 => 1));
// test
$t->expect('LimeAssertionFailedException');
$actual->is($expected);
// @Test: is() throws an exception if keys are unexpected
// fixtures
$actual = new LimeTesterArray(array(0 => 1));
$expected = new LimeTesterArray(array());
// test
$t->expect('LimeAssertionFailedException');
$actual->is($expected);
// @Test: is() throws an exception if values don't match
// fixtures
$actual = new LimeTesterArray(array(0 => 1));
$expected = new LimeTesterArray(array(0 => 2));
// test
$t->expect('LimeAssertionFailedException');
$actual->is($expected);
示例3: TestException
$t->is($value, 'Foobar', 'The correct value has been returned');
// @Test: Return values can be stubbed based on method parameters
// test
$m->testMethod()->returns('Foobar');
$m->testMethod(1)->returns('More foobar');
$m->replay();
$value1 = $m->testMethod();
$value2 = $m->testMethod(1);
// assertions
$t->is($value1, 'Foobar', 'The correct value has been returned');
$t->is($value2, 'More foobar', 'The correct value has been returned');
// @Test: Exceptions can be stubbed
// fixtures
$m->testMethod()->throws('TestException');
$m->replay();
$t->expect('TestException');
// test
$m->testMethod();
// @Test: Exceptions can be stubbed using objects
// fixtures
$m->testMethod()->throws(new TestException());
$m->replay();
$t->expect('TestException');
// TODO: It would be good if we could test for the exact object
// test
$m->testMethod();
// @Test: ->verify() fails if a method was not called
// test
$m->testMethod();
$m->replay();
// assertions
示例4: tmpfile
$resource = tmpfile();
$expected = new LimeTesterResource($resource);
$t->ok(LimeTester::create($resource) == $expected, 'The correct object was created');
fclose($resource);
// @Test: register() registers a new tester for a given class
LimeTester::register('TestClass', 'TestClassTester');
$object = new TestClass();
$expected = new TestClassTester($object);
$t->ok(LimeTester::create($object) == $expected, 'The correct object was created');
// @Test: register() registers a new tester for a given interface
LimeTester::register('TestInterface', 'TestInterfaceTester');
$object = new TestInterfaceClass();
$expected = new TestInterfaceTester($object);
$t->ok(LimeTester::create($object) == $expected, 'The correct object was created');
// @Test: unregister() removes any custom testers for a given class
LimeTester::register('TestClass', 'TestClassTester');
LimeTester::unregister('TestClass');
$object = new TestClass();
$expected = new LimeTesterObject($object);
$t->ok(LimeTester::create($object) == $expected, 'The correct object was created');
// @Test: create() creates a tester also for subclasses of a registered tester
LimeTester::register('TestClass', 'TestClassTester');
$object = new TestSubClass();
$expected = new TestClassTester($object);
$t->ok(LimeTester::create($object) == $expected, 'The correct object was created');
// @Test: register() throws an exception if the tester class does not exist
$t->expect('InvalidArgumentException');
LimeTester::register('TestClass', 'FoobarTester');
// @Test: register() throws an exception if the tester does not implement LimeTesterInterface
$t->expect('InvalidArgumentException');
LimeTester::register('TestClass', 'InvalidTester');
示例5: array
// test
$r->run();
$t->diag('The exception handlers are called when a test throws an exception');
// fixtures
$mock = $t->mock('Mock', array('strict' => true));
$r = new LimeTestRunner();
$r->addTest(array($mock, 'testThrowsException'), '', '', 0);
$r->addExceptionHandler(array($mock, 'handleExceptionFailed'));
$r->addExceptionHandler(array($mock, 'handleExceptionSuccessful'));
$mock->testThrowsException()->throws('Exception');
$mock->method('handleExceptionFailed')->returns(false);
$mock->method('handleExceptionSuccessful')->returns(true);
$mock->replay();
// test
$r->run();
$t->diag('If no exception handler returns true, the exception is thrown again');
// fixtures
$mock = $t->mock('Mock', array('strict' => true));
$r = new LimeTestRunner();
$r->addTest(array($mock, 'testThrowsException'), '', '', 0);
$r->addExceptionHandler(array($mock, 'handleExceptionFailed'));
$mock->testThrowsException()->throws('Exception');
$mock->method('handleExceptionFailed')->returns(false);
$mock->replay();
// test
$t->expect('Exception');
try {
$r->run();
$t->fail('The exception was thrown');
} catch (Exception $e) {
}
示例6: dirname
<?php
/*
* This file is part of the Lime framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
require_once dirname(__FILE__) . '/setup.php';
LimeAnnotationSupport::enable();
$t = new LimeTest();
// @Test
$t->expect(new RuntimeException("Foobar"));
echo "Test 1\n";
throw new RuntimeException("Foobar");
// @Test
$t->expect(new RuntimeException("Foobar", 1));
echo "Test 2\n";
throw new RuntimeException("Foobar", 0);
// @Test
$t->expect(new RuntimeException("Foobar", 1));
echo "Test 3\n";
throw new RuntimeException("Foobar", 1);
示例7: array
// @Test: ->verify() passes if a method is expected both with any and with concrete parameters
// test
$m->method('testMethod')->once();
$m->testMethod(1, 'foobar');
$m->replay();
$m->testMethod('ramble on');
$m->testMethod(1, 'foobar');
$m->verify();
// assertions
$t->is(count($m->__lime_getInvocationTrace()), 2, 'Two tests passed');
// @Test: An exception is thrown if methods are called in the wrong order
// fixtures
$m->method1();
$m->method2();
$m->replay();
$t->expect('LimeMockException');
// test
$m->method2();
// @Test: An exception is thrown if too many methods are called
// test
$m->method1();
$m->replay();
$m->method1();
$t->expect('LimeMockException');
$m->method2();
// @Test: If the option "nice" is set, ->verify() fails if methods were called in the wrong order
// test
$m = LimeMock::create('TestClass', array('strict' => true, 'nice' => true));
$m->method1();
$m->method2();
$m->method3();