Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit 64483f9

Browse files
committed
Tests: Finish unit tests
1 parent 1f3b6bb commit 64483f9

File tree

8 files changed

+201
-64
lines changed

8 files changed

+201
-64
lines changed

.github/workflows/code_analysis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
run: composer ecs
2020

2121
- name: Unit tests
22-
run: composer tests
22+
run: composer tester
2323

2424
name: ${{ matrix.actions.name }}
2525
runs-on: ubuntu-latest

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/composer.lock
2-
/vendor/
3-
/tests/output/
2+
/vendor
3+
/tests/output
4+
/tests/lock
5+
/tests/temp

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"phpstan": "phpstan analyze src --level 6",
2828
"ecs": "ecs check src --set psr12",
2929
"ecs-fix": "ecs check src --set psr12 --fix",
30-
"tests": "tester tests"
30+
"tester": "tester tests"
3131
},
3232
"replace": {
3333
"jakubboucek/composer-vendor-checker": "self.version"

src/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function exceptionMode(): self
8383
* - `int`: Severity mode: `E_USER_ERROR` | `E_USER_WARNING` | `E_USER_NOTICE` | `E_USER_DEPRECATED`
8484
*
8585
* @param int $errorMode
86-
* @return $this
86+
* @return self
8787
*/
8888
public function errorMode(int $errorMode = E_USER_ERROR): self
8989
{

src/Cache/FileCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function isExists($key): bool
6060
}
6161

6262
/**
63-
* @param mixed $key
63+
* @param mixed $key
6464
* @return string
6565
*/
6666
private function getCacheFile($key): string

tests/Checker.compare.phpt

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use JakubBoucek\ComposerConsistency\ComposerConsistency;
6+
use Tester\Assert;
7+
use Tester\Environment;
8+
use Tester\TestCase;
9+
10+
require __DIR__ . '/../vendor/autoload.php';
11+
12+
Environment::setup();
13+
14+
/** @testCase */
15+
class ComposerConsistencyCompareReqsTest extends TestCase
16+
{
17+
private const TEMP_DIR = __DIR__ . '/temp';
18+
19+
protected function setUp(): void
20+
{
21+
@mkdir(self::TEMP_DIR, 0777, true);
22+
}
23+
24+
public function getCompareReqsData(): array
25+
{
26+
return [
27+
[
28+
['nette/tester' => '1.23'],
29+
['nette/tester' => '1.23'],
30+
[]
31+
],
32+
[
33+
['nette/tester' => '1.23'],
34+
['nette/tester' => '4.56'],
35+
['nette/tester' => ['required' => '1.23', 'installed' => '4.56']]
36+
],
37+
[
38+
[],
39+
['nette/tester' => '4.56'],
40+
['nette/tester' => ['required' => null, 'installed' => '4.56']]
41+
],
42+
[
43+
['nette/tester' => '1.23'],
44+
[],
45+
['nette/tester' => ['required' => '1.23', 'installed' => null]]
46+
]
47+
48+
];
49+
}
50+
51+
/**
52+
* @param array $required
53+
* @param array $installed
54+
* @param array $result
55+
* @dataProvider getCompareReqsData
56+
*/
57+
public function testSame(array $required, array $installed, array $result): void
58+
{
59+
$checker = new ComposerConsistency(self::TEMP_DIR);
60+
Assert::with(
61+
$checker,
62+
function () use ($required, $installed, $result) {
63+
/** @noinspection PhpUndefinedMethodInspection */
64+
Assert::same($result, $this->compareReqs($required, $installed));
65+
}
66+
);
67+
}
68+
}
69+
70+
(new ComposerConsistencyCompareReqsTest())->run();

tests/FileCacheTest.phpt

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use JakubBoucek\ComposerConsistency\Cache\FileCache;
6+
use Tester\Assert;
7+
use Tester\Environment;
8+
use Tester\Helpers;
9+
use Tester\TestCase;
10+
11+
require __DIR__ . '/../vendor/autoload.php';
12+
13+
Environment::setup();
14+
15+
/** @testCase */
16+
class FileCacheTest extends TestCase
17+
{
18+
private const TEMP_DIR = __DIR__ . '/temp/cache';
19+
private const LOCK_DIR = __DIR__ . '/lock';
20+
21+
protected function setUp(): void
22+
{
23+
@mkdir(self::LOCK_DIR, 0777, true);
24+
@mkdir(self::TEMP_DIR, 0777, true);
25+
Environment::lock('cache', self::LOCK_DIR);
26+
Helpers::purge(self::TEMP_DIR);
27+
}
28+
29+
protected function getDataKeysValues(): array
30+
{
31+
return [
32+
['foo', 'bar', 'kopo'],
33+
[123, 456, 789],
34+
[new stdClass(), [true], null],
35+
];
36+
}
37+
38+
/**
39+
* @var mixed $value
40+
* @var mixed $key
41+
* @dataProvider getDataKeysValues
42+
*/
43+
public function testCacheMatchContent($key, $value): void
44+
{
45+
$cache = new FileCache(self::TEMP_DIR);
46+
47+
$cache->write($key, $value);
48+
Assert::true($cache->isValid($key, $value));
49+
}
50+
51+
/**
52+
* @var mixed $key
53+
* @var mixed $value
54+
* @var mixed $invalidValue
55+
* @dataProvider getDataKeysValues
56+
*/
57+
public function testCacheUnmatchContent($key, $value, $invalidValue): void
58+
{
59+
$cache = new FileCache(self::TEMP_DIR);
60+
61+
$cache->write($key, $value);
62+
Assert::false($cache->isValid($key, $invalidValue));
63+
}
64+
65+
/**
66+
* @var mixed $key
67+
* @var mixed $value
68+
* @dataProvider getDataKeysValues
69+
*/
70+
public function testCacheCheckExists($key, $value): void
71+
{
72+
$cache = new FileCache(self::TEMP_DIR);
73+
74+
$cache->write($key, $value);
75+
Assert::true($cache->isExists($key));
76+
}
77+
78+
/**
79+
* @var mixed $key
80+
* @var mixed $value
81+
* @var mixed $invalidKey
82+
* @dataProvider getDataKeysValues
83+
*/
84+
public function testCacheCheckNotExists($key, $value, $invalidKey): void
85+
{
86+
$cache = new FileCache(self::TEMP_DIR);
87+
88+
$cache->write($key, $value);
89+
Assert::false($cache->isExists($invalidKey));
90+
}
91+
92+
/**
93+
* @var mixed $key
94+
* @var mixed $value
95+
* @var mixed $invalidKey
96+
* @dataProvider getDataKeysValues
97+
*/
98+
public function testCacheCheckInvalidate($key, $value): void
99+
{
100+
$cache = new FileCache(self::TEMP_DIR);
101+
102+
$cache->write($key, $value);
103+
$cache->invalidate($key);
104+
Assert::false($cache->isExists($key));
105+
}
106+
107+
/**
108+
* @var mixed $key
109+
* @var mixed $value
110+
* @var mixed $invalidKey
111+
* @dataProvider getDataKeysValues
112+
*/
113+
public function testCacheCheckInvalidateOther($key, $value, $invalidKey): void
114+
{
115+
$cache = new FileCache(self::TEMP_DIR);
116+
117+
$cache->write($key, $value);
118+
$cache->invalidate($invalidKey);
119+
Assert::true($cache->isExists($key));
120+
}
121+
}
122+
123+
(new FileCacheTest())->run();

0 commit comments

Comments
 (0)