-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from zaporylie/add-tests
Add unit tests
- Loading branch information
Showing
5 changed files
with
101 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit backupGlobals="true" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
</php> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace zaporylie\ComposerDrupalOptimizations\Tests; | ||
|
||
use Composer\IO\NullIO; | ||
use PHPUnit\Framework\TestCase; | ||
use zaporylie\ComposerDrupalOptimizations\Cache; | ||
|
||
class CacheTest extends TestCase | ||
{ | ||
|
||
/** | ||
* Tests if data is not malformed and only valid array from valid provider | ||
* is processed. | ||
* | ||
* @param $provided | ||
* @param $expected | ||
* | ||
* @dataProvider provideReadTest | ||
*/ | ||
public function testRead($provided, $expected) | ||
{ | ||
$cache = new class(new NullIO(), 'test') extends Cache { | ||
protected static $lowestTags = [ | ||
'vendor/package' => 'version', | ||
]; | ||
protected function readFile($file) | ||
{ | ||
// Remove provider - used only for tests. | ||
if (0 === strpos($file, 'provider-vendor$')) { | ||
$file = substr($file, 16); | ||
} | ||
return $file; | ||
} | ||
public function removeLegacyTags(array $data) | ||
{ | ||
$data['status'] = 'ok'; | ||
return $data; | ||
} | ||
}; | ||
static::assertEquals($expected, $cache->read($provided)); | ||
} | ||
|
||
/** | ||
* Test data. | ||
*/ | ||
function provideReadTest() | ||
{ | ||
yield 'normal' => ['{"a":"b"}', '{"a":"b"}']; | ||
yield 'falsy' => ['{"a":"b"', '{"a":"b"']; | ||
yield 'empty' => ['', '']; | ||
yield 'matching-incorrect-provider' => ['{"provider":"vendor"}', '{"provider":"vendor"}']; | ||
yield 'matching' => ['provider-vendor${"provider":"vendor"}', '{"provider":"vendor","status":"ok"}']; | ||
} | ||
} |