Skip to content

Commit

Permalink
Add support for ObjectState Matcher (is, has) (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas authored Dec 30, 2018
1 parent 7b89610 commit 3cc6b98
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* **Removed** for now removed features.
* **Fixed** for any bug fixes.
* **Security** in case of vulnerabilities.


## [0.1.1] 2018-12-29
### Added
* support for ObjectState Matcher (is, has)

### Removed
* unused symfony/finder dependency


## Unreleased
## [0.1.0] 2018-12-29
### Added
* first initial release
23 changes: 23 additions & 0 deletions spec/Proget/Tests/BazSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace spec\Proget\Tests;

use Proget\Tests\Baz;
use PhpSpec\ObjectBehavior;

class BazSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType(Baz::class);
}

public function it_should_allow_to_enable(): void
{
$this->enable();

$this->shouldBeEnabled();
}
}
10 changes: 7 additions & 3 deletions src/Reflection/ObjectBehaviorMethodsClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
return $subjectReflection->getMethod($methodName, new OutOfClassScope());
}

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

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

return new ObjectBehaviorMethodReflection(
$this->broker->getClass(
$this->getSourceClassName($classReflection)
)->getMethod($methodName, new OutOfClassScope())
$this->broker->getClass($sourceClass)->getMethod($methodName, new OutOfClassScope())
);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Baz.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,23 @@

class Baz
{
/**
* @var bool
*/
private $enabled = false;

public function someInt(): int
{
return 10;
}

public function enable(): void
{
$this->enabled = true;
}

public function isEnabled(): bool
{
return $this->enabled;
}
}

0 comments on commit 3cc6b98

Please sign in to comment.