Skip to content

Commit 16c73bc

Browse files
authored
Remove deprecated setMethods, add test for index, and remove ddev from CircleCI (#9)
1 parent ade12ff commit 16c73bc

File tree

8 files changed

+70
-66
lines changed

8 files changed

+70
-66
lines changed

.circleci/config.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
version: 2.0
1+
version: 2.1
22
jobs:
33
build:
4-
machine:
5-
image: ubuntu-2004:202010-01
4+
docker:
5+
- image: circleci/php:7.3
66
environment:
77
CC_TEST_REPORTER_ID: 7b1ac919c90c8ea384b4998b267e0f629185a26ffdf0f96ef4f4a09f53488ed2
8+
XDEBUG_MODE: coverage
89
working_directory: ~/repo
910
steps:
1011
- checkout
1112
- run:
12-
name: Setup DDEV
13-
command: |
14-
curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh && bash install_ddev.sh
15-
- run:
16-
name: Setup Code Climate test-reporter
13+
name: Set up Code Climate test-reporter
1714
command: |
1815
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
1916
chmod +x ./cc-test-reporter
2017
- run:
2118
name: Run tests
2219
command: |
23-
ddev start
24-
ddev xdebug
25-
ddev composer install
20+
composer install
2621
./cc-test-reporter before-build
27-
ddev exec ./vendor/bin/phpunit --testsuite all --coverage-clover clover.xml
22+
./vendor/bin/phpunit --testsuite all --coverage-clover clover.xml
2823
sed -i 's+/var/www/html/+/home/circleci/repo/+g' clover.xml
2924
./cc-test-reporter after-build --coverage-input-type clover --exit-code $?

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
vendor
33
composer.lock
44
coverage
5+
.vscode
6+
.phpunit*

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ Creating a double for the body object with plain phpunit might look like this:
2020
```php
2121
$organ = $this->getMockBuilder(Organ::class)
2222
->disableOriginalConstructor()
23-
->setMethods(['getName'])
23+
->onlyMethods(['getName'])
2424
->getMock();
2525

2626
$organ->method('getName')->willReturn('brain');
2727

2828
$system = $this->getMockBuilder(System::class)
2929
->disableOriginalConstructor()
30-
->setMethods(['getOrgan'])
30+
->onlyMethods(['getOrgan'])
3131
->getMock();
3232

3333
$system->method('getOrgan')->willReturn($organ);
3434

3535
$body = $this->getMockBuilder(Body::class)
3636
->disableOriginalConstructor()
37-
->setMethods(['getSystem'])
37+
->onlyMethods(['getSystem'])
3838
->getMock();
3939

4040
$body->method('getSystem')->willReturn($system);

phpunit.xml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
<phpunit
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
4-
verbose="false">
5-
6-
<testsuites>
7-
<testsuite name="all">
8-
<directory suffix="Test.php" phpVersion="7.2" phpVersionOperator=">=">test</directory>
9-
</testsuite>
10-
</testsuites>
11-
12-
<filter>
13-
<whitelist processUncoveredFilesFromWhitelist="true">
14-
<directory suffix=".php">src</directory>
15-
</whitelist>
16-
</filter>
17-
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" verbose="false">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="all">
10+
<directory suffix="Test.php" phpVersion="7.2" phpVersionOperator="&gt;=">test</directory>
11+
</testsuite>
12+
</testsuites>
1813
</phpunit>

src/Chain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function build($objectClass)
7272
$builder = $this->getBuilder($objectClass);
7373

7474
if (!empty($methods)) {
75-
$builder->setMethods($methods);
75+
$builder->onlyMethods($methods);
7676
}
7777
$mock = $builder->getMockForAbstractClass();
7878

test/ChainTest.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
class ChainTest extends TestCase
1414
{
15-
public function test() {
15+
public function test()
16+
{
1617
$organNames = (new Sequence())->add('mouth')->add('stomach');
1718

1819
$organ = (new Chain($this))
@@ -33,7 +34,8 @@ public function test() {
3334
$this->assertEquals($body->getSystem('digestive')->getOrgan('mouth')->getName(), 'mouth');
3435
}
3536

36-
public function test2() {
37+
public function test2()
38+
{
3739
$organNames = (new Sequence())->add('mouth')->add('stomach');
3840

3941
$organ = (new Chain($this))
@@ -56,7 +58,8 @@ public function test2() {
5658
}
5759

5860

59-
public function test3() {
61+
public function test3()
62+
{
6063
$organs = (new Options())
6164
->add('mouth', Organ::class)
6265
->add('stomach', Organ::class);
@@ -81,7 +84,8 @@ public function test3() {
8184
$this->assertEquals(json_encode(['stomach']), json_encode($chain->getStoredInput('organ')));
8285
}
8386

84-
public function test4() {
87+
public function test4()
88+
{
8589
$this->expectExceptionMessage("blah");
8690

8791
$system = (new Chain($this))
@@ -94,24 +98,27 @@ public function test4() {
9498
$body->getSystem("blah");
9599
}
96100

97-
public function testNonExistentMethod() {
98-
$this->expectExceptionMessage("method blah does not exist in MockChainTest\Anatomy\Organ");
99-
(new Chain($this))
101+
public function testNonExistentMethod()
102+
{
103+
$this->expectExceptionMessage('Trying to set mock method "blah" with onlyMethods');
104+
(new Chain($this))
100105
->add(Organ::class, 'blah', null)
101106
->getMock();
102107
}
103108

104-
public function testUsingAdddIncorrectly() {
105-
$this->expectExceptionMessage("You should use the add method before using addd.");
106-
(new Chain($this))->addd("hello");
109+
public function testUsingAdddIncorrectly()
110+
{
111+
$this->expectExceptionMessage("You should use the add method before using addd.");
112+
(new Chain($this))->addd("hello");
107113
}
108114

109-
public function testNonExistentOption() {
115+
public function testNonExistentOption()
116+
{
110117
$this->expectExceptionMessage('Option digestive does not exist');
111118
$options = new Options();
112119
$mock = (new Chain($this))
113120
->add(Body::class, 'getSystem', $options)
114121
->getMock();
115122
$mock->getSystem("digestive");
116123
}
117-
}
124+
}

test/OptionsTest.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@
88

99
class OptionsTest extends TestCase
1010
{
11-
public function test() {
12-
$options = new Options();
13-
$options->add("hello", "goodbye");
14-
$options->add("hola", "chao");
15-
$options->add("multi", (new Sequence())->add('adieu')->add('shalom'));
11+
public function test()
12+
{
13+
$options = new Options();
14+
$options->add("hello", "goodbye");
15+
$options->add("hola", "chao");
16+
$options->add("multi", (new Sequence())->add('adieu')->add('shalom'));
1617

17-
$this->assertEquals(json_encode($options->options()), json_encode(["hello", "hola", "multi"]));
18-
$this->assertEquals($options->return("hello"), "goodbye");
19-
$this->assertEquals($options->return("hola"), "chao");
20-
$this->assertEquals($options->return("multi"), "adieu");
21-
$this->assertEquals($options->return("multi"), "shalom");
22-
$this->assertEquals($options->return("multi"), "shalom");
23-
$this->assertNull($options->return('not-an-option'));
24-
}
25-
}
18+
$this->assertEquals(json_encode($options->options()), json_encode(["hello", "hola", "multi"]));
19+
$this->assertEquals($options->return("hello"), "goodbye");
20+
$this->assertEquals($options->return("hola"), "chao");
21+
$this->assertEquals($options->return("multi"), "adieu");
22+
$this->assertEquals($options->return("multi"), "shalom");
23+
$this->assertEquals($options->return("multi"), "shalom");
24+
$this->assertNull($options->return('not-an-option'));
25+
$options->index(2);
26+
$this->assertEquals(2, $options->getIndex());
27+
}
28+
}

test/SequenceTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
class SequenceTest extends TestCase
1212
{
13-
public function test() {
13+
public function test()
14+
{
1415
$sequence = new Sequence();
1516
$sequence->add(null);
1617
$sequence->add(1);
@@ -22,16 +23,17 @@ public function test() {
2223
$this->assertEquals($sequence->return(), 2);
2324
}
2425

25-
public function testSequenceThroughChain() {
26-
$sequence = (new Sequence())
26+
public function testSequenceThroughChain()
27+
{
28+
$sequence = (new Sequence())
2729
->add(null)
2830
->add("hello");
2931

30-
$mock = (new Chain($this))
32+
$mock = (new Chain($this))
3133
->add(Organ::class, 'getName', $sequence)
3234
->getMock();
3335

34-
$this->assertNull($mock->getName());
35-
$this->assertEquals("hello", $mock->getName());
36+
$this->assertNull($mock->getName());
37+
$this->assertEquals("hello", $mock->getName());
3638
}
37-
}
39+
}

0 commit comments

Comments
 (0)