私が生成する古典的なphpunitスタイルを使用して、symfony2ヘルパーでテストします。私はサービスを受けることができ、問題ないと断言できます。
// public function testGetServiceUrl() { $ecservice = $this->getModule('Symfony2')->grabServiceFromContainer("ecservice"); をテストします。
$this->assertEquals("https://ecoconnect2.niwa.co.nz/services", $ecservice->getServiceUrl());
$this->assertEquals("xxx", $ecservice->getServiceUrl());
}
ただし、アサーションが失敗する 2 番目のケースでは、例外が発生します。
Trying to test get service url (demoTest::testGetServiceUrl) - Failed
PHP Fatal error: Call to a member function getResponse() on a non-object in /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/src/Codeception/Util/Framework.php on line 30
PHP Stack trace:
PHP 1. {main}() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/codecept:0
PHP 2. Symfony\Component\Console\Application->run() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/codecept:38
PHP 3. Symfony\Component\Console\Application->doRun() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:106
PHP 4. Symfony\Component\Console\Command\Command->run() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:193
PHP 5. Codeception\Command\Run->execute() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:240
PHP 6. Codeception\Codecept->runSuite() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/src/Codeception/Command/Run.php:74
PHP 7. Codeception\SuiteManager->run() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/src/Codeception/Codecept.php:110
PHP 8. Codeception\PHPUnit\Runner->doEnhancedRun() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/src/Codeception/SuiteManager.php:132
PHP 9. PHPUnit_Framework_TestSuite->run() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:107
PHP 10. PHPUnit_Framework_TestSuite->runTest() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745
PHP 11. PHPUnit_Framework_TestCase->run() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775
PHP 12. PHPUnit_Framework_TestResult->run() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:776
PHP 13. PHPUnit_Framework_TestResult->addFailure() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:698
PHP 14. Codeception\PHPUnit\Listener->addFailure() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:307
PHP 15. Codeception\PHPUnit\Listener->fire() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:24
PHP 16. Symfony\Component\EventDispatcher\EventDispatcher->dispatch() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:66
PHP 17. Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:53
PHP 18. call_user_func() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:164
PHP 19. Codeception\Subscriber\Module->failed() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:164
PHP 20. Codeception\Util\Framework->_failed() /Users/watkinsav/workspace/cd/ecoconnect_web/vendor/codeception/codeception/src/Codeception/Subscriber/Module.php:47
これは、Framework.php の _failed() 関数が client-getResponse() を呼び出そうとするためです。また、インスタンス化された応答クラスはありません。
public function _failed(\Codeception\TestCase $test, $fail)
{
if (!$this->client->getResponse()) return;
file_put_contents(\Codeception\Configuration::logDir() . basename($test->getFileName()) . '.page.debug.html', $this->client->getResponse()->getContent());
}
ブログ投稿の例: http://codeception.com/02-12-2013/testing-symfony2.html余分な行がいくつかありますが、問題は解決しません。
もう一度ありがとう アンドリュー