-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add phpspecs as spec for better tests 🚀
- Loading branch information
Showing
170 changed files
with
12,615 additions
and
226 deletions.
There are no files selected for viewing
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
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
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
99 changes: 99 additions & 0 deletions
99
spec/PhpSpec/CodeAnalysis/MagicAwareAccessInspectorSpec.php
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,99 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\PhpSpec\CodeAnalysis; | ||
|
||
use PhpSpec\CodeAnalysis\AccessInspector; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class MagicAwareAccessInspectorSpec extends ObjectBehavior | ||
{ | ||
public function let(AccessInspector $accessInspector) | ||
{ | ||
$this->beConstructedWith($accessInspector); | ||
} | ||
|
||
public function it_should_be_an_access_inspector() | ||
{ | ||
$this->shouldImplement('PhpSpec\CodeAnalysis\AccessInspector'); | ||
} | ||
|
||
public function it_should_detect_a_magic_getter_if_no_value_is_given() | ||
{ | ||
$this->isPropertyReadable(new ObjectWithMagicGet, 'property')->shouldReturn(true); | ||
} | ||
|
||
public function it_should_detect_a_magic_setter_if_a_value_is_given() | ||
{ | ||
$this->isPropertyWritable(new ObjectWithMagicSet, 'property', true)->shouldReturn(true); | ||
} | ||
|
||
public function it_should_detect_a_magic_call_method() | ||
{ | ||
$this->isMethodCallable(new ObjectWithMagicCall, 'method')->shouldreturn(true); | ||
} | ||
|
||
public function it_should_not_detect_a_getter_if_there_is_no_magic_getter_and_wrapped_inspector_finds_none(AccessInspector $accessInspector) | ||
{ | ||
$accessInspector->isPropertyReadable(new \stdClass(), 'foo')->willReturn(false); | ||
|
||
$this->isPropertyReadable(new \stdClass(), 'foo')->shouldReturn(false); | ||
} | ||
|
||
public function it_should_detect_a_getter_if_there_is_no_magic_getter_but_wrapped_inspector_finds_one(AccessInspector $accessInspector) | ||
{ | ||
$accessInspector->isPropertyReadable(new \stdClass(), 'foo')->willReturn(true); | ||
|
||
$this->isPropertyReadable(new \stdClass(), 'foo')->shouldReturn(true); | ||
} | ||
|
||
public function it_should_not_detect_a_setter_if_there_is_no_magic_setter_and_wrapped_inspector_finds_none(AccessInspector $accessInspector) | ||
{ | ||
$accessInspector->isPropertyWritable(new \stdClass(), 'foo')->willReturn(false); | ||
|
||
$this->isPropertyWritable(new \stdClass(), 'foo')->shouldReturn(false); | ||
} | ||
|
||
public function it_should_detect_a_setter_if_there_is_no_magic_setter_but_wrapped_inspector_finds_one(AccessInspector $accessInspector) | ||
{ | ||
$accessInspector->isPropertyWritable(new \stdClass(), 'foo')->willReturn(true); | ||
|
||
$this->isPropertyWritable(new \stdClass(), 'foo')->shouldReturn(true); | ||
} | ||
|
||
public function it_should_detect_a_method_if_there_is_no_magic_caller_and_wrapped_inspector_finds_none(AccessInspector $accessInspector) | ||
{ | ||
$accessInspector->isMethodCallable(new \stdClass(), 'foo')->willReturn(false); | ||
|
||
$this->isMethodCallable(new \stdClass(), 'foo')->shouldReturn(false); | ||
} | ||
|
||
public function it_should_detect_a_method_if_there_is_no_magic_caller_but_wrapped_inspector_finds_one(AccessInspector $accessInspector) | ||
{ | ||
$accessInspector->isMethodCallable(new \stdClass(), 'foo')->willReturn(true); | ||
|
||
$this->isMethodCallable(new \stdClass(), 'foo')->shouldReturn(true); | ||
} | ||
} | ||
|
||
class ObjectWithMagicGet | ||
{ | ||
public function __get($name) | ||
{ | ||
} | ||
} | ||
|
||
class ObjectWithMagicSet | ||
{ | ||
public function __set($name, $value) | ||
{ | ||
} | ||
} | ||
|
||
class ObjectWithMagicCall | ||
{ | ||
public function __call($name, $args) | ||
{ | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
spec/PhpSpec/CodeAnalysis/StaticRejectingNamespaceResolverSpec.php
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\PhpSpec\CodeAnalysis; | ||
|
||
use PhpSpec\CodeAnalysis\DisallowedNonObjectTypehintException; | ||
use PhpSpec\CodeAnalysis\NamespaceResolver; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class StaticRejectingNamespaceResolverSpec extends ObjectBehavior | ||
{ | ||
public function let(NamespaceResolver $namespaceResolver) | ||
{ | ||
$this->beConstructedWith($namespaceResolver); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('PhpSpec\CodeAnalysis\NamespaceResolver'); | ||
} | ||
|
||
public function it_delegates_analysis_to_wrapped_resolver(NamespaceResolver $namespaceResolver) | ||
{ | ||
$this->analyse('foo'); | ||
|
||
$namespaceResolver->analyse('foo')->shouldhaveBeenCalled(); | ||
} | ||
|
||
public function it_delegates_resolution_to_wrapped_resolver(NamespaceResolver $namespaceResolver) | ||
{ | ||
$namespaceResolver->resolve('Bar')->willReturn('Foo\Bar'); | ||
|
||
$this->resolve('Bar')->shouldReturn('Foo\Bar'); | ||
} | ||
|
||
public function it_does_not_allow_resolution_of_non_object_types() | ||
{ | ||
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('int'); | ||
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('float'); | ||
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('string'); | ||
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('bool'); | ||
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('iterable'); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
spec/PhpSpec/CodeAnalysis/TokenizedNamespaceResolverSpec.php
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,128 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\PhpSpec\CodeAnalysis; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
class TokenizedNamespaceResolverSpec extends ObjectBehavior | ||
{ | ||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('PhpSpec\CodeAnalysis\NamespaceResolver'); | ||
} | ||
|
||
public function it_resolves_types_outside_of_namespaces() | ||
{ | ||
$this->analyse(' | ||
<?php | ||
class Foo | ||
{ | ||
} | ||
'); | ||
|
||
$this->resolve('Bar')->shouldReturn('Bar'); | ||
$this->resolve('Bar')->shouldReturn('Bar'); | ||
} | ||
|
||
public function it_resolves_types_from_current_namespace() | ||
{ | ||
$this->analyse(' | ||
<?php | ||
namespace Baz; | ||
class Foo | ||
{ | ||
} | ||
'); | ||
|
||
$this->resolve('Foo')->shouldReturn('Baz\Foo'); | ||
$this->resolve('Bar')->shouldReturn('Baz\Bar'); | ||
} | ||
|
||
public function it_resolves_types_with_use_statements() | ||
{ | ||
$this->analyse(' | ||
<?php | ||
namespace Baz; | ||
use Boz\Bar; | ||
class Foo | ||
{ | ||
} | ||
'); | ||
|
||
$this->resolve('Foo')->shouldReturn('Baz\Foo'); | ||
$this->resolve('Bar')->shouldReturn('Boz\Bar'); | ||
} | ||
|
||
public function it_resolves_types_with_use_aliases() | ||
{ | ||
$this->analyse(' | ||
<?php | ||
namespace Baz; | ||
use Boz\Bar as Biz; | ||
class Foo | ||
{ | ||
} | ||
'); | ||
|
||
$this->resolve('Foo')->shouldReturn('Baz\Foo'); | ||
$this->resolve('Biz')->shouldReturn('Boz\Bar'); | ||
} | ||
|
||
public function it_resolves_types_with_partial_use_statements() | ||
{ | ||
$this->analyse(' | ||
<?php | ||
namespace Baz; | ||
use Boz\Bar; | ||
class Foo | ||
{ | ||
function it_something(Bar\Baz $boz) | ||
{ | ||
} | ||
} | ||
'); | ||
|
||
$this->resolve('Foo')->shouldReturn('Baz\Foo'); | ||
$this->resolve('Bar\Baz')->shouldReturn('Boz\Bar\Baz'); | ||
} | ||
|
||
public function it_resolves_types_from_grouped_use_statements() | ||
{ | ||
$this->analyse(' | ||
<?php | ||
namespace Baz; | ||
use Boz\{Fiz, Buz}; | ||
class Foo | ||
{ | ||
function it_something(Fiz $fiz, Buz $buz) | ||
{ | ||
} | ||
} | ||
'); | ||
|
||
$this->resolve('Fiz')->shouldReturn('Boz\Fiz'); | ||
$this->resolve('Buz')->shouldReturn('Boz\Buz'); | ||
} | ||
} |
Oops, something went wrong.