diff --git a/.circleci/config.yml b/.circleci/config.yml index 8cf3de8..02f4369 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,29 +1,24 @@ -version: 2.0 +version: 2.1 jobs: build: - machine: - image: ubuntu-2004:202010-01 + docker: + - image: circleci/php:7.3 environment: CC_TEST_REPORTER_ID: 7b1ac919c90c8ea384b4998b267e0f629185a26ffdf0f96ef4f4a09f53488ed2 + XDEBUG_MODE: coverage working_directory: ~/repo steps: - checkout - run: - name: Setup DDEV - command: | - curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh && bash install_ddev.sh - - 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 - 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 $? diff --git a/.gitignore b/.gitignore index f42423d..983cd7b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ vendor composer.lock coverage +.vscode +.phpunit* \ No newline at end of file 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/phpunit.xml b/phpunit.xml index b4d7c1e..444f5b1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,18 +1,13 @@ - - - - - test - - - - - - src - - - + + + + + src + + + + + test + + 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(); diff --git a/test/ChainTest.php b/test/ChainTest.php index 7f7757e..e12a8ee 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('Trying to set mock method "blah" with onlyMethods'); + (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..8f52ed9 100644 --- a/test/OptionsTest.php +++ b/test/OptionsTest.php @@ -8,18 +8,21 @@ 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')); + $options->index(2); + $this->assertEquals(2, $options->getIndex()); + } +} 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 +}