phpunit

How can I get PHPUnit MockObjects to return different values based on a parameter?

孤者浪人 提交于 2019-12-17 15:26:07
问题 I've got a PHPUnit mock object that returns 'return value' no matter what its arguments: // From inside a test... $mock = $this->getMock('myObject', 'methodToMock'); $mock->expects($this->any)) ->method('methodToMock') ->will($this->returnValue('return value')); What I want to be able to do is return a different value based on the arguments passed to the mock method. I've tried something like: $mock = $this->getMock('myObject', 'methodToMock'); // methodToMock('one') $mock->expects($this->any

How are integration tests written for interacting with external API?

。_饼干妹妹 提交于 2019-12-17 15:10:03
问题 First up, where my knowledge is at: Unit Tests are those which test a small piece of code (single methods, mostly). Integration Tests are those which test the interaction between multiple areas of code (which hopefully already have their own Unit Tests). Sometimes, parts of the code under test requires other code to act in a particular way. This is where Mocks & Stubs come in. So, we mock/stub out a part of the code to perform very specifically. This allows our Integration Test to run

Can't install PHPUnit via PEAR, requires PEAR Installer >= 1.9.2, can't upgrade PEAR from 1.9.0

吃可爱长大的小学妹 提交于 2019-12-17 06:53:07
问题 I read the other PHPUnit installation questions but haven't had any success. What is going on with my PEAR install? $ sudo pear update-channels Updating channel "components.ez.no" Channel "components.ez.no" is up to date Updating channel "doc.php.net" Channel "doc.php.net" is up to date Updating channel "pear.php.net" Channel "pear.php.net" is up to date Updating channel "pear.phpunit.de" Channel "pear.phpunit.de" is up to date Updating channel "pear.symfony-project.com" Channel "pear.symfony

Can't install PHPUnit via PEAR, requires PEAR Installer >= 1.9.2, can't upgrade PEAR from 1.9.0

独自空忆成欢 提交于 2019-12-17 06:52:23
问题 I read the other PHPUnit installation questions but haven't had any success. What is going on with my PEAR install? $ sudo pear update-channels Updating channel "components.ez.no" Channel "components.ez.no" is up to date Updating channel "doc.php.net" Channel "doc.php.net" is up to date Updating channel "pear.php.net" Channel "pear.php.net" is up to date Updating channel "pear.phpunit.de" Channel "pear.phpunit.de" is up to date Updating channel "pear.symfony-project.com" Channel "pear.symfony

PHPUnit assert that an exception was thrown?

拈花ヽ惹草 提交于 2019-12-17 04:14:46
问题 Does anyone know whether there is an assert or something like that which can test whether an exception was thrown in the code being tested? 回答1: <?php require_once 'PHPUnit/Framework.php'; class ExceptionTest extends PHPUnit_Framework_TestCase { public function testException() { $this->expectException(InvalidArgumentException::class); // or for PHPUnit < 5.2 // $this->setExpectedException(InvalidArgumentException::class); //...and then add your test code that generates the exception

Symfony 2 functional tests with mocked services

给你一囗甜甜゛ 提交于 2019-12-14 03:39:34
问题 I have a controller I'd like to create functional tests for. This controller makes HTTP requests to an external API via a MyApiClient class. I need to mock out this MyApiClient class, so I can test how my controller responds for given responses (e.g. what will it do if the MyApiClient class returns a 500 response). I have no problems creating a mocked version of the MyApiClient class via the standard PHPUnit mockbuilder: The problem I'm having is getting my controller to use this object for

PHPUnit_Util_Skeleton_Test not found in CakePHP

北城以北 提交于 2019-12-14 02:27:16
问题 I'm able to run my individual tests for each model in a plugin called Agg, but when I try to run a CakeTestSuite, then I get an error. class ModelsTest extends CakeTestSuite { public static function suite() { $suite = new CakeTestSuite('All model tests'); $suite->addTestDirectory(TESTS . 'Case' . DS . 'Model'); return $suite; } } Running that suite generates this error. Fatal error: Class 'PHPUnit_Util_Skeleton_Test' not found in C:\work\zend\cake\Cake\TestSuite\CakeTestSuiteCommand.php on

Whats the right place for testhelper-classes? (phpunit/best practise)

China☆狼群 提交于 2019-12-14 02:18:23
问题 I want to test my application with PHPUnit. So I have my application-classes and a second tree with test-classes as usual. Now I need for some test a kind of Dummy/Mock-Objects and I want to know where I should place them. Is it a different usecase and it should be place in common lib folder or what is to prefer? 回答1: In the cases where I don't use mock objects but instead create a throw-away subclass for the test case, I name the class with the test case's prefix and place it in the same

How to PHPUnit test a group function within Yii on Netbeans?

微笑、不失礼 提交于 2019-12-13 22:10:32
问题 I've problem when I used PHPUnit test framework Yii in Netbeans. I've a class DemoController.php extends from class Controller of Yii. And I've a class DemoControllerTest.php. I can test all function in class by PHPUnit, but when I used @group annotation (support by PHPUnit) to test a group function. It not runs . DemoController.php: class DemoController extends Controller { public function add($a, $b) { return $a + $b; } } DemoControllerTest.php: require_once dirname(__FILE__) . '/..

phpunit cannot find Class, PHP Fatal error

不问归期 提交于 2019-12-13 20:40:30
问题 I get phpunit and install it as this link using the simplest way for test purposes. I just download the phpunit.phar file, chmod & rename & move to /usr/local/bin Then, I run phpunit --version, its ok. PHPUnit 3.7.27 by Sebastian Bergmann I write a simple test public function testSomething(){ $this -> assertTrue(true) } Then I go into the source file folder, phpunit --colors Test It works. So, I decide write a complex demo. My project folder structure is like this. Project Name --> app -->