Skip to content

Commit

Permalink
Enhancement: Add tests where prophesize(), willExtend(), and willImpl…
Browse files Browse the repository at this point in the history
…ement() are used in helper method
  • Loading branch information
localheinz committed Mar 1, 2020
1 parent 9cfcd2a commit 23ded47
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ final class ExampleTest extends Framework\TestCase

// ...
}

public function testSomethingDifferent(): void
{
$testDouble = $this->createProphecy()->reveal();

// ...
}

private function createProphecy()
{
return $this->prophesize(SomeModel::class);
}

}
```

Expand Down Expand Up @@ -101,6 +114,18 @@ final class ExampleTest extends Framework\TestCase

// ...
}

public function testSomethingDifferent(): void
{
$testDouble = $this->createProphecy()->reveal();

// ...
}

private function createProphecy()
{
return $this->prophesize(SomeModel::class)->willExtend(SomeInterface::class);
}
}
```

Expand Down Expand Up @@ -137,6 +162,18 @@ final class ExampleTest extends Framework\TestCase

// ...
}

public function testSomethingDifferent(): void
{
$testDouble = $this->createProphecy()->reveal();

// ...
}

private function createProphecy()
{
return $this->prophesize(SomeModel::class)->willImplement(SomeInterface::class);
}
}
```

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ includes:

parameters:
ignoreErrors:
- '#^Method .* has no return typehint specified\.$#'
- '#^Property .* has no typehint specified\.$#'
inferPrivatePropertyTypeFromConstructor: true
level: max
Expand Down
23 changes: 23 additions & 0 deletions test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,27 @@ public function testInTestMethod(): void
self::assertEquals('bar', $testDouble->getFoo());
self::assertEquals(5, $testDouble->doubleTheNumber(2));
}

public function testInHelperMethod(): void
{
$prophecy = $this->createProphecy();

$prophecy
->getFoo()
->willReturn('bar');

$prophecy
->doubleTheNumber(Argument::is(2))
->willReturn(5);

$testDouble = $prophecy->reveal();

self::assertEquals('bar', $testDouble->getFoo());
self::assertEquals(5, $testDouble->doubleTheNumber(2));
}

private function createProphecy()
{
return $this->prophesize(Src\BaseModel::class);
}
}
19 changes: 19 additions & 0 deletions test/StaticAnalysis/Test/ObjectProphecy/WillExtendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,23 @@ public function testInTestMethod(): void

self::assertSame('Hmm', $subject->baz($prophecy->reveal()));
}

public function testInHelperMethod(): void
{
$prophecy = $this->createProphecy();

$prophecy
->baz()
->shouldBeCalled()
->willReturn('Hmm');

$subject = new Src\BaseModel();

self::assertSame('Hmm', $subject->baz($prophecy->reveal()));
}

private function createProphecy()
{
return $this->prophesize()->willExtend(Src\Baz::class);
}
}
19 changes: 19 additions & 0 deletions test/StaticAnalysis/Test/ObjectProphecy/WillImplementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,23 @@ public function testInTestMethod(): void

self::assertSame('Oh', $subject->bar($prophecy->reveal()));
}

public function testInHelperMethod(): void
{
$prophecy = $this->createProphecy();

$prophecy
->bar()
->shouldBeCalled()
->willReturn('Oh');

$subject = new Src\BaseModel();

self::assertSame('Oh', $subject->bar($prophecy->reveal()));
}

private function createProphecy()
{
return $this->prophesize(Src\Foo::class)->willImplement(Src\Bar::class);
}
}

0 comments on commit 23ded47

Please sign in to comment.