Skip to content

Commit

Permalink
Merge pull request #5 from sirbrillig/add/invalidexpectationexception
Browse files Browse the repository at this point in the history
Throw exception when accessing invalid property on an Expectation
  • Loading branch information
sirbrillig committed May 31, 2016
2 parents f3b1573 + d67ed6f commit 45bfa01
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Spies/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __get( $key ) {
$this->negation = true;
return $this;
}
throw new InvalidExpectationException( 'Invalid property: "' . $key . '" does not exist on this Expectation' );
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Spies/InvalidExpectationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
namespace Spies;

class InvalidExpectationException extends \Exception {
}
12 changes: 12 additions & 0 deletions tests/ExpectationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public function test_times_is_not_met_if_spy_is_called_more_than_that_many_times
$this->assertInternalType( 'string', $expectation->verify() );
}

public function test_once_as_property_throws_an_error() {
$this->expectException( \Spies\InvalidExpectationException::class );
$spy = \Spies\make_spy();
\Spies\expect_spy( $spy )->to_have_been_called->once;
}

public function test_once_is_met_if_spy_is_called_once() {
$spy = \Spies\make_spy();
$expectation = \Spies\expect_spy( $spy )->to_have_been_called->once();
Expand All @@ -100,6 +106,12 @@ public function test_once_is_not_met_if_spy_is_not_called() {
$this->assertInternalType( 'string', $expectation->verify() );
}

public function test_twice_as_property_throws_an_error() {
$this->expectException( \Spies\InvalidExpectationException::class );
$spy = \Spies\make_spy();
\Spies\expect_spy( $spy )->to_have_been_called->twice;
}

public function test_once_is_not_met_if_spy_is_called_twice() {
$spy = \Spies\make_spy();
$expectation = \Spies\expect_spy( $spy )->to_have_been_called->once();
Expand Down

0 comments on commit 45bfa01

Please sign in to comment.