-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Token value object and use it in all places we do tokenisation to remove magic arrays --------- Co-authored-by: Jacob Dreesen <jacob@hdreesen.de>
- Loading branch information
1 parent
b3ed048
commit 5f8ebb6
Showing
12 changed files
with
377 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace spec\PhpSpec\Util\Token; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use PhpSpec\Util\Token; | ||
use PhpSpec\Util\Token\ArrayToken; | ||
|
||
class ArrayTokenSpec extends ObjectBehavior | ||
{ | ||
function let() | ||
{ | ||
$this->beConstructedThrough( | ||
[Token::class, 'fromPhpToken'], | ||
[[T_CATCH, 'catch', 100]] | ||
); | ||
} | ||
|
||
function it_equals_the_string_in_token_array_it_was_created_with() | ||
{ | ||
$this->equals('catch')->shouldBe(true); | ||
} | ||
|
||
function it_stringifys_as_the_string_in_token_array_it_was_created_with() | ||
{ | ||
$this->asString()->shouldBe('catch'); | ||
} | ||
|
||
function it_does_not_equal_string_different_to_one_in_token_array_it_was_created_with() | ||
{ | ||
$this->equals('bar')->shouldBe(false); | ||
} | ||
|
||
function it_has_same_type_as_token_array_it_was_created_with() | ||
{ | ||
$this->hasType(T_CATCH)->shouldBe(true); | ||
} | ||
|
||
function it_does_not_have_same_type_as_token_different_to_array_it_was_created_with() | ||
{ | ||
$this->hasType(T_FINALLY)->shouldBe(false); | ||
} | ||
|
||
function it_is_in_a_matching_type_list() | ||
{ | ||
$this->isInTypes([T_CATCH])->shouldBe(true); | ||
} | ||
|
||
function it_is_not_in_a_non_matching_type_list() | ||
{ | ||
$this->isInTypes([T_FINALLY])->shouldBe(false); | ||
} | ||
|
||
function it_has_a_line() | ||
{ | ||
$this->getLine()->shouldBe(100); | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace spec\PhpSpec\Util\Token; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use PhpSpec\Util\Token; | ||
use PhpSpec\Util\Token\StringToken; | ||
|
||
class StringTokenSpec extends ObjectBehavior | ||
{ | ||
function let() | ||
{ | ||
$this->beConstructedThrough( | ||
[Token::class, 'fromPhpToken'], | ||
['f'] | ||
); | ||
} | ||
|
||
function it_equals_the_string_it_was_created_with() | ||
{ | ||
$this->equals('f')->shouldBe(true); | ||
} | ||
|
||
function it_stringifys_as_the_string_it_was_created_with() | ||
{ | ||
$this->asString()->shouldBe('f'); | ||
} | ||
|
||
function it_does_not_equal_different_string() | ||
{ | ||
$this->equals('b')->shouldBe(false); | ||
} | ||
|
||
function it_does_not_have_type() | ||
{ | ||
$this->hasType(T_CATCH)->shouldBe(false); | ||
} | ||
|
||
function it_is_never_in_a_type_list() | ||
{ | ||
$this->isInTypes([T_CATCH])->shouldBe(false); | ||
} | ||
|
||
function it_does_not_have_a_line() | ||
{ | ||
$this->getLine()->shouldBeNull(); | ||
} | ||
} |
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
Oops, something went wrong.