Skip to content

Commit 3cc6b98

Browse files
authored
Add support for ObjectState Matcher (is, has) (#4)
1 parent 7b89610 commit 3cc6b98

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111
* **Removed** for now removed features.
1212
* **Fixed** for any bug fixes.
1313
* **Security** in case of vulnerabilities.
14+
15+
16+
## [0.1.1] 2018-12-29
17+
### Added
18+
* support for ObjectState Matcher (is, has)
19+
20+
### Removed
21+
* unused symfony/finder dependency
1422

1523

16-
## Unreleased
24+
## [0.1.0] 2018-12-29
1725
### Added
1826
* first initial release

spec/Proget/Tests/BazSpec.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace spec\Proget\Tests;
6+
7+
use Proget\Tests\Baz;
8+
use PhpSpec\ObjectBehavior;
9+
10+
class BazSpec extends ObjectBehavior
11+
{
12+
public function it_is_initializable()
13+
{
14+
$this->shouldHaveType(Baz::class);
15+
}
16+
17+
public function it_should_allow_to_enable(): void
18+
{
19+
$this->enable();
20+
21+
$this->shouldBeEnabled();
22+
}
23+
}

src/Reflection/ObjectBehaviorMethodsClassReflectionExtension.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
5757
return $subjectReflection->getMethod($methodName, new OutOfClassScope());
5858
}
5959

60+
$sourceClass = $this->getSourceClassName($classReflection);
61+
62+
if (preg_match('/^should(Be|Have)(.+)$/', $methodName)) {
63+
return $this->broker->getClass($sourceClass)->getMethod(str_replace(['shouldBe', 'shouldHave'], ['is', 'has'], $methodName), new OutOfClassScope());
64+
}
65+
6066
return new ObjectBehaviorMethodReflection(
61-
$this->broker->getClass(
62-
$this->getSourceClassName($classReflection)
63-
)->getMethod($methodName, new OutOfClassScope())
67+
$this->broker->getClass($sourceClass)->getMethod($methodName, new OutOfClassScope())
6468
);
6569
}
6670

tests/Baz.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@
66

77
class Baz
88
{
9+
/**
10+
* @var bool
11+
*/
12+
private $enabled = false;
13+
914
public function someInt(): int
1015
{
1116
return 10;
1217
}
18+
19+
public function enable(): void
20+
{
21+
$this->enabled = true;
22+
}
23+
24+
public function isEnabled(): bool
25+
{
26+
return $this->enabled;
27+
}
1328
}

0 commit comments

Comments
 (0)