Skip to content

Commit 17d644f

Browse files
authored
Make naming make sense again (#3)
* Make naming make sense again * Add tests for trait
1 parent 2a83beb commit 17d644f

File tree

8 files changed

+79
-19
lines changed

8 files changed

+79
-19
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Or add the package to your dependencies in `composer.json` and run
3333

3434
## Usage
3535
This package exposes a single trait: `\Sven\LaravelViewAssertions\InteractsWithViews`.
36-
When you `use` this trait in your tests as below, you'll get access to 4 assertions:
36+
When you `use` this trait in your tests as below, you'll get access to several assertions:
3737

3838
```php
3939
<?php
@@ -50,13 +50,15 @@ class ExampleTest extends TestCase
5050
// ...
5151

5252
$this->assertViewExists('some.view-file');
53+
$this->assertViewsExist(['posts.index', 'posts.show']);
5354
}
5455

5556
public function test_it_does_not_create_a_view()
5657
{
5758
// ...
5859

59-
$this->assertViewNotExists('some.view-file');
60+
$this->assertViewDoesNotExist('some.view-file');
61+
$this->assertViewsDoNotExist(['posts.edit', 'posts.create']);
6062
}
6163

6264
public function test_the_view_equals()
@@ -70,7 +72,7 @@ class ExampleTest extends TestCase
7072
{
7173
// ...
7274

73-
$this->assertViewNotEquals('This Is Not The Content You\'re Looking For', 'index');
75+
$this->assertViewDoesNotEqual('This Is Not The Content You\'re Looking For', 'index');
7476
}
7577
}
7678
```

src/Constraints/ViewNotEquals.php renamed to src/Constraints/ViewDoesNotEqual.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66

7-
class ViewNotEquals extends Constraint
7+
class ViewDoesNotEqual extends Constraint
88
{
99
public function __construct(protected string $expected)
1010
{

src/Constraints/ViewNotExists.php renamed to src/Constraints/ViewDoesNotExist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use InvalidArgumentException;
66
use PHPUnit\Framework\Constraint\Constraint;
77

8-
class ViewNotExists extends Constraint
8+
class ViewDoesNotExist extends Constraint
99
{
1010
protected function matches($other): bool
1111
{

src/InteractsWithViews.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Sven\LaravelViewAssertions;
44

55
use PHPUnit\Framework\Assert as PHPUnit;
6+
use Sven\LaravelViewAssertions\Constraints\ViewDoesNotEqual;
7+
use Sven\LaravelViewAssertions\Constraints\ViewDoesNotExist;
68
use Sven\LaravelViewAssertions\Constraints\ViewEquals;
79
use Sven\LaravelViewAssertions\Constraints\ViewExists;
8-
use Sven\LaravelViewAssertions\Constraints\ViewNotEquals;
9-
use Sven\LaravelViewAssertions\Constraints\ViewNotExists;
1010

1111
trait InteractsWithViews
1212
{
@@ -15,18 +15,44 @@ public function assertViewExists(string $name, string $message = ''): void
1515
PHPUnit::assertThat($name, new ViewExists, $message);
1616
}
1717

18+
public function assertViewsExist(array $names): void
19+
{
20+
foreach ($names as $name) {
21+
$this->assertViewExists($name);
22+
}
23+
}
24+
25+
public function assertViewDoesNotExist(string $name, string $message = ''): void
26+
{
27+
PHPUnit::assertThat($name, new ViewDoesNotExist, $message);
28+
}
29+
30+
/** @deprecated */
1831
public function assertViewNotExists(string $name, string $message = ''): void
1932
{
20-
PHPUnit::assertThat($name, new ViewNotExists, $message);
33+
$this->assertViewDoesNotExist($name, $message);
34+
}
35+
36+
public function assertViewsDoNotExist(array $names): void
37+
{
38+
foreach ($names as $name) {
39+
$this->assertViewDoesNotExist($name);
40+
}
2141
}
2242

2343
public function assertViewEquals(string $expected, string $view, string $message = ''): void
2444
{
2545
PHPUnit::assertThat($view, new ViewEquals($expected), $message);
2646
}
2747

48+
public function assertViewDoesNotEqual(string $expected, string $view, string $message = ''): void
49+
{
50+
PHPUnit::assertThat($view, new ViewDoesNotEqual($expected), $message);
51+
}
52+
53+
/** @deprecated */
2854
public function assertViewNotEquals(string $expected, string $view, string $message = ''): void
2955
{
30-
PHPUnit::assertThat($view, new ViewNotEquals($expected), $message);
56+
$this->assertViewDoesNotEqual($expected, $view, $message);
3157
}
3258
}

tests/Constraints/ViewNotEqualsTest.php renamed to tests/Constraints/ViewDoesNotEqualTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
namespace Sven\LaravelViewAssertions\Tests\Constraints;
44

5-
use Sven\LaravelViewAssertions\Constraints\ViewNotEquals;
5+
use Sven\LaravelViewAssertions\Constraints\ViewDoesNotEqual;
66
use Sven\LaravelViewAssertions\Tests\TestCase;
77

8-
class ViewNotEqualsTest extends TestCase
8+
class ViewDoesNotEqualTest extends TestCase
99
{
1010
/** @test */
1111
public function the_contents_of_a_view_do_not_equal_the_given_value(): void
1212
{
1313
$this->makeView('viewname', 'Contents of the view');
1414

15-
$constraint = new ViewNotEquals('Other contents');
15+
$constraint = new ViewDoesNotEqual('Other contents');
1616

1717
$this->assertTrue($constraint->evaluate('viewname', '', true));
1818
}
@@ -22,7 +22,7 @@ public function the_contents_of_a_view_equal_the_given_value(): void
2222
{
2323
$this->makeView('viewname', 'Contents of the view');
2424

25-
$constraint = new ViewNotEquals('Contents of the view');
25+
$constraint = new ViewDoesNotEqual('Contents of the view');
2626

2727
$this->assertFalse($constraint->evaluate('viewname', '', true));
2828
}

tests/Constraints/ViewNotExistsTest.php renamed to tests/Constraints/ViewDoesNotExistTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
namespace Sven\LaravelViewAssertions\Tests\Constraints;
44

5-
use Sven\LaravelViewAssertions\Constraints\ViewNotExists;
5+
use Sven\LaravelViewAssertions\Constraints\ViewDoesNotExist;
66
use Sven\LaravelViewAssertions\Tests\TestCase;
77

8-
class ViewNotExistsTest extends TestCase
8+
class ViewDoesNotExistTest extends TestCase
99
{
1010
/** @test */
1111
public function a_view_exists(): void
1212
{
13-
$this->assertTrue((new ViewNotExists)->evaluate('does-not-exist', '', true));
13+
$this->assertTrue((new ViewDoesNotExist)->evaluate('does-not-exist', '', true));
1414
}
1515

1616
/** @test */
1717
public function a_view_does_not_exist(): void
1818
{
1919
$this->makeView('exists');
2020

21-
$this->assertFalse((new ViewNotExists)->evaluate('exists', '', true));
21+
$this->assertFalse((new ViewDoesNotExist)->evaluate('exists', '', true));
2222
}
2323
}

tests/Constraints/ViewExistsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public function a_view_exists(): void
1212
{
1313
$this->makeView('exists');
1414

15-
$this->assertTrue((new ViewExists)->evaluate('exists', '', true));
15+
$this->assertTrue((new ViewExists)->evaluate('exists', returnResult: true));
1616
}
1717

1818
/** @test */
1919
public function a_view_does_not_exist(): void
2020
{
21-
$this->assertFalse((new ViewExists)->evaluate('does-not-exist', '', true));
21+
$this->assertFalse((new ViewExists)->evaluate('does-not-exist', returnResult: true));
2222
}
2323
}

tests/InteractsWithViewsTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Sven\LaravelViewAssertions\Tests;
4+
5+
use Sven\LaravelViewAssertions\InteractsWithViews;
6+
7+
class InteractsWithViewsTest extends TestCase
8+
{
9+
use InteractsWithViews;
10+
11+
/** @test */
12+
public function views_existance(): void
13+
{
14+
$this->makeView('exists');
15+
$this->makeView('also-exists');
16+
17+
$this->assertViewExists('exists');
18+
$this->assertViewsExist(['exists', 'also-exists']);
19+
$this->assertViewDoesNotExist('does-not-exist');
20+
$this->assertViewsDoNotExist(['does-not-exist', 'also-does-not-exist']);
21+
}
22+
23+
/** @test */
24+
public function views_equal(): void
25+
{
26+
$this->makeView('one', 'hello');
27+
$this->makeView('two', 'goodbye');
28+
29+
$this->assertViewEquals('hello', 'one');
30+
$this->assertViewDoesNotEqual('farewell', 'two');
31+
}
32+
}

0 commit comments

Comments
 (0)