From 367152ecf8c466a1b8566776e9dc84b7b4a4f695 Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 09:08:32 -0400 Subject: [PATCH 01/10] Ignore vscode --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f42423d..a03e4fa 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor composer.lock coverage +.vscode From 9d31c4d74afd73bce0ed70443fd0291bd47c933a Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 09:11:14 -0400 Subject: [PATCH 02/10] Switch deprecated setMethods to onlyMethods --- README.md | 6 +++--- src/Chain.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3559da6..9075bb3 100644 --- a/README.md +++ b/README.md @@ -20,21 +20,21 @@ Creating a double for the body object with plain phpunit might look like this: ```php $organ = $this->getMockBuilder(Organ::class) ->disableOriginalConstructor() - ->setMethods(['getName']) + ->onlyMethods(['getName']) ->getMock(); $organ->method('getName')->willReturn('brain'); $system = $this->getMockBuilder(System::class) ->disableOriginalConstructor() - ->setMethods(['getOrgan']) + ->onlyMethods(['getOrgan']) ->getMock(); $system->method('getOrgan')->willReturn($organ); $body = $this->getMockBuilder(Body::class) ->disableOriginalConstructor() - ->setMethods(['getSystem']) + ->onlyMethods(['getSystem']) ->getMock(); $body->method('getSystem')->willReturn($system); diff --git a/src/Chain.php b/src/Chain.php index dc542d3..31a9b94 100644 --- a/src/Chain.php +++ b/src/Chain.php @@ -72,7 +72,7 @@ private function build($objectClass) $builder = $this->getBuilder($objectClass); if (!empty($methods)) { - $builder->setMethods($methods); + $builder->onlyMethods($methods); } $mock = $builder->getMockForAbstractClass(); From 12abe3b3e7b8e0bf3dac53681371af2b728e42c7 Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 09:18:46 -0400 Subject: [PATCH 03/10] Update phpunit.xml schema --- phpunit.xml | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index b4d7c1e..444f5b1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,18 +1,13 @@ - - - - - test - - - - - - src - - - + + + + + src + + + + + test + + From 519765204790db1779fc734fce2e5bb2ae7b7ea7 Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 09:23:37 -0400 Subject: [PATCH 04/10] Try new image --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8cf3de8..5671c17 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,8 +1,8 @@ version: 2.0 jobs: build: - machine: - image: ubuntu-2004:202010-01 + docker: + - image: circleci/php:7.3 environment: CC_TEST_REPORTER_ID: 7b1ac919c90c8ea384b4998b267e0f629185a26ffdf0f96ef4f4a09f53488ed2 working_directory: ~/repo From aa0fe39c0af62bb4136070011f3c80549fc36f1a Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 09:30:03 -0400 Subject: [PATCH 05/10] Trying new thing w/o ddev --- .circleci/config.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5671c17..669faf5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,9 +9,10 @@ jobs: steps: - checkout - run: - name: Setup DDEV + name: Setup Xdebug command: | - curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh && bash install_ddev.sh + sudo pecl channel-update pecl.php.net + sudo pecl install xdebug && sudo docker-php-ext-enable xdebug - run: name: Setup Code Climate test-reporter command: | @@ -20,10 +21,8 @@ jobs: - run: name: Run tests command: | - ddev start - ddev xdebug - ddev composer install + composer install ./cc-test-reporter before-build - ddev exec ./vendor/bin/phpunit --testsuite all --coverage-clover clover.xml + ./vendor/bin/phpunit --testsuite all --coverage-clover clover.xml sed -i 's+/var/www/html/+/home/circleci/repo/+g' clover.xml ./cc-test-reporter after-build --coverage-input-type clover --exit-code $? From aeb76088ddb908f3c21368ca8f31430e9a5e1c24 Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 09:30:54 -0400 Subject: [PATCH 06/10] No Xdebug needed --- .circleci/config.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 669faf5..23af25b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,11 +8,6 @@ jobs: working_directory: ~/repo steps: - checkout - - run: - name: Setup Xdebug - command: | - sudo pecl channel-update pecl.php.net - sudo pecl install xdebug && sudo docker-php-ext-enable xdebug - run: name: Setup Code Climate test-reporter command: | From b34784c7b7d69cb0b9b7507cb9deb39f3dd1d363 Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 09:34:29 -0400 Subject: [PATCH 07/10] Some code style fixes --- test/ChainTest.php | 31 +++++++++++++++++++------------ test/OptionsTest.php | 29 +++++++++++++++-------------- test/SequenceTest.php | 16 +++++++++------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/test/ChainTest.php b/test/ChainTest.php index 7f7757e..7405090 100644 --- a/test/ChainTest.php +++ b/test/ChainTest.php @@ -12,7 +12,8 @@ class ChainTest extends TestCase { - public function test() { + public function test() + { $organNames = (new Sequence())->add('mouth')->add('stomach'); $organ = (new Chain($this)) @@ -33,7 +34,8 @@ public function test() { $this->assertEquals($body->getSystem('digestive')->getOrgan('mouth')->getName(), 'mouth'); } - public function test2() { + public function test2() + { $organNames = (new Sequence())->add('mouth')->add('stomach'); $organ = (new Chain($this)) @@ -56,7 +58,8 @@ public function test2() { } - public function test3() { + public function test3() + { $organs = (new Options()) ->add('mouth', Organ::class) ->add('stomach', Organ::class); @@ -81,7 +84,8 @@ public function test3() { $this->assertEquals(json_encode(['stomach']), json_encode($chain->getStoredInput('organ'))); } - public function test4() { + public function test4() + { $this->expectExceptionMessage("blah"); $system = (new Chain($this)) @@ -94,19 +98,22 @@ public function test4() { $body->getSystem("blah"); } - public function testNonExistentMethod() { - $this->expectExceptionMessage("method blah does not exist in MockChainTest\Anatomy\Organ"); - (new Chain($this)) + public function testNonExistentMethod() + { + $this->expectExceptionMessage("method blah does not exist in MockChainTest\Anatomy\Organ"); + (new Chain($this)) ->add(Organ::class, 'blah', null) ->getMock(); } - public function testUsingAdddIncorrectly() { - $this->expectExceptionMessage("You should use the add method before using addd."); - (new Chain($this))->addd("hello"); + public function testUsingAdddIncorrectly() + { + $this->expectExceptionMessage("You should use the add method before using addd."); + (new Chain($this))->addd("hello"); } - public function testNonExistentOption() { + public function testNonExistentOption() + { $this->expectExceptionMessage('Option digestive does not exist'); $options = new Options(); $mock = (new Chain($this)) @@ -114,4 +121,4 @@ public function testNonExistentOption() { ->getMock(); $mock->getSystem("digestive"); } -} \ No newline at end of file +} diff --git a/test/OptionsTest.php b/test/OptionsTest.php index c55a956..e826eb4 100644 --- a/test/OptionsTest.php +++ b/test/OptionsTest.php @@ -8,18 +8,19 @@ class OptionsTest extends TestCase { - public function test() { - $options = new Options(); - $options->add("hello", "goodbye"); - $options->add("hola", "chao"); - $options->add("multi", (new Sequence())->add('adieu')->add('shalom')); + public function test() + { + $options = new Options(); + $options->add("hello", "goodbye"); + $options->add("hola", "chao"); + $options->add("multi", (new Sequence())->add('adieu')->add('shalom')); - $this->assertEquals(json_encode($options->options()), json_encode(["hello", "hola", "multi"])); - $this->assertEquals($options->return("hello"), "goodbye"); - $this->assertEquals($options->return("hola"), "chao"); - $this->assertEquals($options->return("multi"), "adieu"); - $this->assertEquals($options->return("multi"), "shalom"); - $this->assertEquals($options->return("multi"), "shalom"); - $this->assertNull($options->return('not-an-option')); - } -} \ No newline at end of file + $this->assertEquals(json_encode($options->options()), json_encode(["hello", "hola", "multi"])); + $this->assertEquals($options->return("hello"), "goodbye"); + $this->assertEquals($options->return("hola"), "chao"); + $this->assertEquals($options->return("multi"), "adieu"); + $this->assertEquals($options->return("multi"), "shalom"); + $this->assertEquals($options->return("multi"), "shalom"); + $this->assertNull($options->return('not-an-option')); + } +} diff --git a/test/SequenceTest.php b/test/SequenceTest.php index 54ec6b6..f8a2a6c 100644 --- a/test/SequenceTest.php +++ b/test/SequenceTest.php @@ -10,7 +10,8 @@ class SequenceTest extends TestCase { - public function test() { + public function test() + { $sequence = new Sequence(); $sequence->add(null); $sequence->add(1); @@ -22,16 +23,17 @@ public function test() { $this->assertEquals($sequence->return(), 2); } - public function testSequenceThroughChain() { - $sequence = (new Sequence()) + public function testSequenceThroughChain() + { + $sequence = (new Sequence()) ->add(null) ->add("hello"); - $mock = (new Chain($this)) + $mock = (new Chain($this)) ->add(Organ::class, 'getName', $sequence) ->getMock(); - $this->assertNull($mock->getName()); - $this->assertEquals("hello", $mock->getName()); + $this->assertNull($mock->getName()); + $this->assertEquals("hello", $mock->getName()); } -} \ No newline at end of file +} From e22b6487ecb11013f1b228b495f52f73df69b2ed Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 09:37:10 -0400 Subject: [PATCH 08/10] Update expected exception method from onlyMethods --- .circleci/config.yml | 3 ++- .phpunit.result.cache | 1 + test/ChainTest.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.circleci/config.yml b/.circleci/config.yml index 23af25b..dd04f17 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,11 +5,12 @@ jobs: - image: circleci/php:7.3 environment: CC_TEST_REPORTER_ID: 7b1ac919c90c8ea384b4998b267e0f629185a26ffdf0f96ef4f4a09f53488ed2 + XDEBUG_MODE: coverage working_directory: ~/repo steps: - checkout - run: - name: Setup Code Climate test-reporter + name: Set up Code Climate test-reporter command: | curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter chmod +x ./cc-test-reporter diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..2a01f04 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":614:{a:2:{s:7:"defects";a:1:{s:46:"MockChainTest\ChainTest::testNonExistentMethod";i:3;}s:5:"times";a:10:{s:29:"MockChainTest\ChainTest::test";d:0.007;s:30:"MockChainTest\ChainTest::test2";d:0.001;s:30:"MockChainTest\ChainTest::test3";d:0.001;s:30:"MockChainTest\ChainTest::test4";d:0.001;s:46:"MockChainTest\ChainTest::testNonExistentMethod";d:0;s:49:"MockChainTest\ChainTest::testUsingAdddIncorrectly";d:0;s:46:"MockChainTest\ChainTest::testNonExistentOption";d:0;s:31:"MockChainTest\OptionsTest::test";d:0;s:32:"MockChainTest\SequenceTest::test";d:0;s:52:"MockChainTest\SequenceTest::testSequenceThroughChain";d:0;}}} \ No newline at end of file diff --git a/test/ChainTest.php b/test/ChainTest.php index 7405090..e12a8ee 100644 --- a/test/ChainTest.php +++ b/test/ChainTest.php @@ -100,7 +100,7 @@ public function test4() public function testNonExistentMethod() { - $this->expectExceptionMessage("method blah does not exist in MockChainTest\Anatomy\Organ"); + $this->expectExceptionMessage('Trying to set mock method "blah" with onlyMethods'); (new Chain($this)) ->add(Organ::class, 'blah', null) ->getMock(); From 7cd52ddc6f8ceaeadfae0e38e75779636511958f Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 10:27:07 -0400 Subject: [PATCH 09/10] Version 2.1 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dd04f17..02f4369 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,4 @@ -version: 2.0 +version: 2.1 jobs: build: docker: From 5acf28fc4c390c52bfa1822c45e9dbe7db162a33 Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 20 Aug 2021 11:20:40 -0400 Subject: [PATCH 10/10] Add test for index --- .gitignore | 1 + .phpunit.result.cache | 1 - test/OptionsTest.php | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 .phpunit.result.cache diff --git a/.gitignore b/.gitignore index a03e4fa..983cd7b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor composer.lock coverage .vscode +.phpunit* \ No newline at end of file diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 2a01f04..0000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":614:{a:2:{s:7:"defects";a:1:{s:46:"MockChainTest\ChainTest::testNonExistentMethod";i:3;}s:5:"times";a:10:{s:29:"MockChainTest\ChainTest::test";d:0.007;s:30:"MockChainTest\ChainTest::test2";d:0.001;s:30:"MockChainTest\ChainTest::test3";d:0.001;s:30:"MockChainTest\ChainTest::test4";d:0.001;s:46:"MockChainTest\ChainTest::testNonExistentMethod";d:0;s:49:"MockChainTest\ChainTest::testUsingAdddIncorrectly";d:0;s:46:"MockChainTest\ChainTest::testNonExistentOption";d:0;s:31:"MockChainTest\OptionsTest::test";d:0;s:32:"MockChainTest\SequenceTest::test";d:0;s:52:"MockChainTest\SequenceTest::testSequenceThroughChain";d:0;}}} \ No newline at end of file diff --git a/test/OptionsTest.php b/test/OptionsTest.php index e826eb4..8f52ed9 100644 --- a/test/OptionsTest.php +++ b/test/OptionsTest.php @@ -22,5 +22,7 @@ public function test() $this->assertEquals($options->return("multi"), "shalom"); $this->assertEquals($options->return("multi"), "shalom"); $this->assertNull($options->return('not-an-option')); + $options->index(2); + $this->assertEquals(2, $options->getIndex()); } }