Skip to content

Commit 8df9953

Browse files
Simplified driver API
1 parent 6083624 commit 8df9953

File tree

6 files changed

+5
-32
lines changed

6 files changed

+5
-32
lines changed

src/Driver.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ public function serialize($data): string;
2222
*/
2323
public function extension(): string;
2424

25-
/**
26-
* Load the contents of a snapshot at a path.
27-
*
28-
* @param string $path
29-
*
30-
* @return mixed
31-
*/
32-
public function load(string $path);
33-
3425
/**
3526
* Match an expectation with a snapshot's actual contents. Should throw an
3627
* `ExpectationFailedException` if it doesn't match. This happens by

src/Drivers/JsonDriver.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ public function extension(): string
2323
return '.json';
2424
}
2525

26-
public function load(string $path)
27-
{
28-
return file_get_contents($path);
29-
}
30-
3126
public function match($expected, $actual)
3227
{
3328
Assert::assertJson($expected);

src/Drivers/VarDriver.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ public function extension(): string
1717
return '.php';
1818
}
1919

20-
public function load(string $path)
21-
{
22-
return include $path;
23-
}
24-
2520
public function match($expected, $actual)
2621
{
27-
Assert::assertEquals($expected, $actual);
22+
$evaluated = eval(substr($expected, strlen('<?php ')));
23+
24+
Assert::assertEquals($evaluated, $actual);
2825
}
2926
}

src/Drivers/XmlDriver.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public function extension(): string
3030
return '.xml';
3131
}
3232

33-
public function load(string $path)
34-
{
35-
return file_get_contents($path);
36-
}
37-
3833
public function match($expected, $actual)
3934
{
4035
Assert::assertEquals(Xml::load($expected), Xml::load($actual));

src/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function has(string $filename): bool
2727
return file_exists($this->path($filename));
2828
}
2929

30-
public function read(string $filename): bool
30+
public function read(string $filename): string
3131
{
3232
return file_get_contents($this->path($filename));
3333
}

src/Snapshot.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,14 @@ public function filename(): string
4343
return $this->id.$this->driver->extension();
4444
}
4545

46-
public function path(): string
47-
{
48-
return $this->filesystem->path($this->filename());
49-
}
50-
5146
public function exists(): bool
5247
{
5348
return $this->filesystem->has($this->filename());
5449
}
5550

5651
public function assertMatches($actual)
5752
{
58-
$this->driver->match($this->driver->load($this->path()), $actual);
53+
$this->driver->match($this->filesystem->read($this->filename()), $actual);
5954
}
6055

6156
public function create($actual)

0 commit comments

Comments
 (0)