diff --git a/.circleci/config.yml b/.circleci/config.yml index 2a48f40..94b583a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,9 +30,13 @@ jobs: name: PHPUnit command: | ENABLE_COVERAGE=false - if [ "<< parameters.php-version >>" == "8" ] && [ "$ENABLE_COVERAGE" == "true" ]; then - XDEBUG_MODE=coverage phpunit --coverage-clover clover.xml - coveralls --coverage_clover=clover.xml -v -o coveralls-upload.json + if [ "<< parameters.php-version >>" == "8.2" ]; then + if ["$ENABLE_COVERAGE" == "true"]; then + XDEBUG_MODE=coverage phpunit --coverage-clover clover.xml + coveralls --coverage_clover=clover.xml -v -o coveralls-upload.json + else + phpunit --display-deprecations + fi else phpunit fi diff --git a/README.md b/README.md index bbdacb7..9360d07 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,20 @@ class HelloWorldTest extends TestCase * Real CircleCI example * https://app.circleci.com/pipelines/github/pmvc/pmvc?branch=master +## PHPUnit Tip +* Show event +``` +phpunit --log-events-text php://stdout +``` + +* show deprecations +``` +phpunit --display-deprecations --testdox +``` + +* trigger PMVC dev dump + * https://github.com/pmvc-plugin/dev/blob/master/tests/DevWithPhpUnitTest.php + ## Install with Composer @@ -82,3 +96,5 @@ class HelloWorldTest extends TestCase * or * composer require pmvc-plugin/unit +## Other Polyfills + * https://github.com/Yoast/PHPUnit-Polyfills diff --git a/src/TestCase.php b/src/TestCase.php index 73d8c31..decc34c 100644 --- a/src/TestCase.php +++ b/src/TestCase.php @@ -17,6 +17,22 @@ public function __construct( } } } + if (!class_exists('PHPUnit_Framework_MockObject_MockBuilder')) { + class PHPUnit_Framework_MockObject_MockBuilder + { + use \PMVC\Alias; + public $caller; + public function __construct(\PMVC\TestCase $testCase, string $type) + { + $this->setDefaultAlias( + new \PHPUnit\Framework\MockObject\MockBuilder( + $testCase, + $type + ) + ); + } + } + } if (!class_exists('TypeError')) { class TypeError extends Exception { @@ -33,6 +49,19 @@ class TypeError extends Exception l(__DIR__ . '/TestCase-5'); } + class PMVCMockBuilder extends \PHPUnit_Framework_MockObject_MockBuilder + { + use Alias; + public function pmvc_onlyMethods($methods) + { + if ($this->isCallable('onlyMethods')) { + return $this->onlyMethods($methods); + } else { + return $this->setMethods($methods); + } + } + } + class PMVCUnitException extends \Exception { public function __construct( @@ -90,6 +119,16 @@ private function _init() } } + protected function getPMVCMockBuilder($className) + { + return new PMVCMockBuilder($this, $className); + } + + protected function dump() + { + fwrite(STDERR, print_r(func_get_args(), true)); + } + protected function altSetup() { $this->_init(); diff --git a/tests/src/PMVCMockBuilderTest.php b/tests/src/PMVCMockBuilderTest.php new file mode 100644 index 0000000..9a969f9 --- /dev/null +++ b/tests/src/PMVCMockBuilderTest.php @@ -0,0 +1,28 @@ +getPMVCMockBuilder(FakeDebugMock::class) + ->pmvc_onlyMethods(['a']) + ->getMock(); + $mock->expects($this->atLeastOnce())->method('a'); + + $actual = $mock->a(); + $this->assertEquals($actual, null); + $this->assertEquals((new FakeDebugMock())->a(), 'foo'); + } +} + +class FakeDebugMock +{ + public function a() + { + return 'foo'; + } +}