Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add tests where prophesize(), willExtend(), and willImplement() are used in helper methods #147

Merged
merged 1 commit into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 testCreateProphecyInTestMethod(): void
self::assertEquals('bar', $testDouble->getFoo());
self::assertEquals(5, $testDouble->doubleTheNumber(2));
}

public function testCreateProphecyInHelperMethod(): 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 testCreateProphecyInTestMethod(): void

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

public function testCreateProphecyInHelperMethod(): 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 testCreateProphecyInTestMethod(): void

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

public function testCreateProphecyInHelperMethod(): 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);
}
}