Run PHPUnit Tests in Certain Order

PHPUnit supports test dependencies via the @depends annotation. Here is an example from the documentation where tests will be run in an order that satisfies dependencies, with each dependent test passing an argument to the next: class StackTest extends PHPUnit_Framework_TestCase { public function testEmpty() { $stack = array(); $this->assertEmpty($stack); return $stack; } /** * @depends … Read more

Mock private method with PHPUnit

Usually you just don’t test or mock the private & protected methods directy. What you want to test is the public API of your class. Everything else is an implementation detail for your class and should not “break” your tests if you change it. That also helps you when you notice that you “can’t get … Read more

How are integration tests written for interacting with external API?

This is more an additional answer to the one already given: Looking through your code, the class GoogleAPIRequest has a hard-encoded dependency of class Request. This prevents you from testing it independently from the request class, so you can’t mock the request. You need to make the request injectable, so you can change it to … Read more

How can I suppress PHPCS warnings using comments?

You can get PHP_CodeSniffer to ignore specific files or lines in a file using comments: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders In this case, the error will be generated on your second class definition, so you’d have to write you second definition like this: // @codingStandardsIgnoreStart class MyClassTest extends \PHPUnit_Framework_TestCase { // @codingStandardsIgnoreEnd // … } But you might also … Read more

How to run a specific phpunit xml testsuite?

Here’s the code as if PHPUnit 3.7.13 $ phpunit –configuration config.xml –testsuite Library $ phpunit –configuration config.xml –testsuite XXX_Form If you want to run a group of the test suites then you can do this <testsuites> <testsuite name=”Library”> <directory>library</directory> </testsuite> <testsuite name=”XXX_Form”> <file>library/XXX/FormTest.php</file> <directory>library/XXX/Form</directory> </testsuite> <testsuite name=”Both”> <directory>library</directory> <file>library/XXX/FormTest.php</file> <directory>library/XXX/Form</directory> </testsuite> </testsuites> Then $ phpunit … Read more