-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Split test cases used in static code analysis
- Loading branch information
1 parent
c804947
commit 373d962
Showing
4 changed files
with
152 additions
and
106 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2018 Jan Gregor Emge-Triebel | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/Jan0707/phpstan-prophecy | ||
*/ | ||
|
||
namespace JanGregor\Prophecy\Test\StaticAnalysis\Test; | ||
|
||
use JanGregor\Prophecy\Test\StaticAnalysis\Src\BaseModel; | ||
use PHPUnit\Framework; | ||
use Prophecy\Argument; | ||
use Prophecy\Prophecy; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @coversNothing | ||
*/ | ||
final class ProphesizeTest extends Framework\TestCase | ||
{ | ||
/** | ||
* @var BaseModel|Prophecy\ObjectProphecy | ||
*/ | ||
private $prophecy; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->prophecy = $this->prophesize(BaseModel::class); | ||
} | ||
|
||
public function testInSetUp(): void | ||
{ | ||
$this->prophecy | ||
->getFoo() | ||
->willReturn('bar'); | ||
|
||
$this->prophecy | ||
->doubleTheNumber(Argument::is(2)) | ||
->willReturn(5); | ||
|
||
$testDouble = $this->prophecy->reveal(); | ||
|
||
self::assertEquals('bar', $testDouble->getFoo()); | ||
self::assertEquals(5, $testDouble->doubleTheNumber(2)); | ||
} | ||
|
||
public function testInTestMethod(): void | ||
{ | ||
$prophecy = $this->prophesize(BaseModel::class); | ||
|
||
$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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2018 Jan Gregor Emge-Triebel | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/Jan0707/phpstan-prophecy | ||
*/ | ||
|
||
namespace JanGregor\Prophecy\Test\StaticAnalysis\Test; | ||
|
||
use JanGregor\Prophecy\Test\StaticAnalysis\Src\BaseModel; | ||
use JanGregor\Prophecy\Test\StaticAnalysis\Src\Baz; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @coversNothing | ||
*/ | ||
final class WillExtendTest extends TestCase | ||
{ | ||
public function testInTestMethod(): void | ||
{ | ||
$prophecy = $this->prophesize()->willExtend(Baz::class); | ||
|
||
$prophecy | ||
->baz() | ||
->shouldBeCalled() | ||
->willReturn('Hmm'); | ||
|
||
$subject = new BaseModel(); | ||
|
||
self::assertSame('Hmm', $subject->baz($prophecy->reveal())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2018 Jan Gregor Emge-Triebel | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/Jan0707/phpstan-prophecy | ||
*/ | ||
|
||
namespace JanGregor\Prophecy\Test\StaticAnalysis\Test; | ||
|
||
use JanGregor\Prophecy\Test\StaticAnalysis\Src\Bar; | ||
use JanGregor\Prophecy\Test\StaticAnalysis\Src\BaseModel; | ||
use JanGregor\Prophecy\Test\StaticAnalysis\Src\Foo; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @coversNothing | ||
*/ | ||
final class WillImplementTest extends Framework\TestCase | ||
{ | ||
public function testInTestMethod(): void | ||
{ | ||
$prophecy = $this->prophesize(Foo::class)->willImplement(Bar::class); | ||
|
||
$prophecy | ||
->bar() | ||
->shouldBeCalled() | ||
->willReturn('Oh'); | ||
|
||
$subject = new BaseModel(); | ||
|
||
self::assertSame('Oh', $subject->bar($prophecy->reveal())); | ||
} | ||
} |