Skip to content

Commit 8603999

Browse files
authored
Support for negation in ObjectState Matcher (#7)
* Fix typo in changelog * Support for negation in ObjectState Matcher
1 parent 3cc6b98 commit 8603999

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
* **Fixed** for any bug fixes.
1313
* **Security** in case of vulnerabilities.
1414

15+
## Unreleased
16+
### Fixed
17+
* support for negation in ObjectState Matcher (not)
1518

16-
## [0.1.1] 2018-12-29
19+
## [0.1.1] 2018-12-30
1720
### Added
1821
* support for ObjectState Matcher (is, has)
1922

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* public attributes
2727
* static properties (with `$this->CONSTANT_NAME`)
2828
* Provides correct class for `getWrappedObject` method
29+
* Support `ObjectState Matcher` and check if appropriate methods exists
2930

3031

3132
## Compatibility

spec/Proget/Tests/BazSpec.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,21 @@ public function it_should_allow_to_enable(): void
2020

2121
$this->shouldBeEnabled();
2222
}
23+
24+
public function it_should_be_disabled_by_default(): void
25+
{
26+
$this->shouldNotBeEnabled();
27+
}
28+
29+
public function it_should_not_have_items_by_default(): void
30+
{
31+
$this->shouldNotHaveItems();
32+
}
33+
34+
public function it_should_allow_to_add_item(): void
35+
{
36+
$this->addItem('item');
37+
38+
$this->shouldHaveItems();
39+
}
2340
}

src/Reflection/ObjectBehaviorMethodsClassReflectionExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
5959

6060
$sourceClass = $this->getSourceClassName($classReflection);
6161

62-
if (preg_match('/^should(Be|Have)(.+)$/', $methodName)) {
63-
return $this->broker->getClass($sourceClass)->getMethod(str_replace(['shouldBe', 'shouldHave'], ['is', 'has'], $methodName), new OutOfClassScope());
62+
if (preg_match('/^should((Not)?)(Be|Have)(.+)$/', $methodName)) {
63+
return $this->broker->getClass($sourceClass)->getMethod(str_replace(['shouldBe', 'shouldNotBe', 'shouldHave', 'shouldNotHave'], ['is', 'is', 'has', 'has'], $methodName), new OutOfClassScope());
6464
}
6565

6666
return new ObjectBehaviorMethodReflection(

tests/Baz.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ class Baz
1111
*/
1212
private $enabled = false;
1313

14+
/**
15+
* @var string[]
16+
*/
17+
private $items = [];
18+
1419
public function someInt(): int
1520
{
1621
return 10;
@@ -25,4 +30,14 @@ public function isEnabled(): bool
2530
{
2631
return $this->enabled;
2732
}
33+
34+
public function addItem(string $item): void
35+
{
36+
$this->items[] = $item;
37+
}
38+
39+
public function hasItems(): bool
40+
{
41+
return count($this->items) > 0;
42+
}
2843
}

0 commit comments

Comments
 (0)