Skip to content

Commit 200b046

Browse files
Add PHPUnit integration
1 parent 2a02b40 commit 200b046

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"autoload-dev": {
3434
"psr-4": {
35-
"Spatie\\TabularAssertions\\Tests\\": "tests/"
35+
"Tests\\": "tests/"
3636
}
3737
},
3838
"scripts": {

src/PHPUnit/TabularAssertions.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Spatie\TabularAssertions\PHPUnit;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Spatie\TabularAssertions\Table;
7+
8+
/** @mixin TestCase */
9+
trait TabularAssertions
10+
{
11+
public function assertMatchesTable(string $expected, array $actual): void
12+
{
13+
[$expected, $actual] = Table::from($expected)->compare($actual);
14+
15+
$this->assertSame($expected, $actual);
16+
}
17+
}

tests/Integration/PHPUnitTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Tests\Integration;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Spatie\TabularAssertions\PHPUnit\TabularAssertions;
7+
8+
class PHPUnitTest extends TestCase
9+
{
10+
use TabularAssertions;
11+
12+
public function test_it_compares_a_table(): void
13+
{
14+
$this->assertMatchesTable('
15+
| id | name | email |
16+
| 20 | John Doe | john@doe.com |
17+
| 1245 | Jane Doe | jane@doe.com |
18+
', [
19+
['id' => 20, 'name' => 'John Doe', 'email' => 'john@doe.com'],
20+
['id' => 1245, 'name' => 'Jane Doe', 'email' => 'jane@doe.com'],
21+
]);
22+
}
23+
}

0 commit comments

Comments
 (0)