Skip to content

Commit 01d21f4

Browse files
authored
chore(tests): Adds missing unit tests (#114)
* Add test case for text class * Define text test suite * Add route test suite * Add array key check * Update dependencies * CS fix * Change location of test-coverage * Add artifact upload * Fix test db access * Ingnore files from test coverage * Rename workflow * DEfine ubuntu version * Add archive docs * Add memcached extension * Remove command * Fix comments * Refactor method * Add use * Add tests * Add tests * Refactor uri class * Remove exception * Add tests method * Runs on push * Add publish docs step * Publish dosc only on push to develop * Fix typo * Rename workflow
1 parent 5ceb300 commit 01d21f4

29 files changed

+668
-262
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Main workflow
2+
on:
3+
push:
4+
jobs:
5+
ci:
6+
runs-on: ubuntu-20.04
7+
env:
8+
DB_NAME: test
9+
DB_PASSWORD: root
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: '7.4'
16+
extensions: imagick, xdebug, memcached
17+
tools: composer:v2
18+
19+
- uses: getong/mariadb-action@v1.1
20+
with:
21+
mysql database: ${{ env.DB_NAME }}
22+
mysql root password: ${{ env.DB_PASSWORD }}
23+
24+
- name: Install new instance
25+
run: ./bin/install.sh root "$DB_PASSWORD" "$DB_NAME" 127.0.0.1 3306
26+
27+
- name: Cache Composer packages
28+
id: composer-cache
29+
uses: actions/cache@v2
30+
with:
31+
path: vendor
32+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-php-
35+
36+
- name: Validate DB schema
37+
run: composer orm:validate
38+
39+
- name: Coding Standards
40+
run: composer cs
41+
42+
- name: Static Analysis
43+
run: composer phpstan
44+
45+
- name: Unit tests
46+
run: composer test:coverage
47+
48+
- name: Generate docs
49+
run: composer docs
50+
51+
- name: Archive test coverage
52+
uses: actions/upload-artifact@v2
53+
with:
54+
name: test_coverage
55+
path: public/reports/test-coverage/
56+
retention-days: 7
57+
58+
- name: Archive docs
59+
uses: actions/upload-artifact@v2
60+
with:
61+
name: docs
62+
path: public/docs
63+
retention-days: 7
64+
65+
- name: Publish docs
66+
if: github.ref == 'refs/heads/develop'
67+
uses: peaceiris/actions-gh-pages@v3
68+
with:
69+
github_token: ${{ secrets.GITHUB_TOKEN }}
70+
publish_dir: ./public/docs

.github/workflows/test.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"scripts": {
4242
"docs": "phpdoc",
4343
"test": "vendor/bin/phpunit tests",
44-
"test:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html public/reports/codecov/",
44+
"test:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html public/reports/test-coverage/",
4545
"orm:create": "doctrine orm:schema-tool:create",
4646
"orm:update": "doctrine orm:clear-cache:metadata && doctrine orm:schema-tool:update --force",
4747
"orm:drop": "doctrine orm:clear-cache:metadata && doctrine orm:schema-tool:drop --full-database --force",
@@ -51,7 +51,6 @@
5151
"app:password": "php bin/console app:password",
5252
"phpstan": "phpstan analyse",
5353
"cs": "vendor/bin/php-cs-fixer fix src --dry-run --ansi",
54-
"cs:fix": "vendor/bin/php-cs-fixer fix src --ansi",
55-
"foo": "doctrine"
54+
"cs:fix": "vendor/bin/php-cs-fixer fix src --ansi"
5655
}
5756
}

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
<directory>./tests/Lib/Util</directory>
1717
<file>./tests/Lib/Util/InputTest.php</file>
1818
</testsuite>
19-
<testsuite name="Request Test Suite">
19+
<testsuite name="Http Test Suite">
2020
<directory>./tests/Lib/Http</directory>
21+
<file>./tests/Lib/Http/BodyTest.php</file>
2122
<file>./tests/Lib/Http/RequestTest.php</file>
23+
<file>./tests/Lib/Http/UriTest.php</file>
2224
</testsuite>
2325
<testsuite name="Router Test Suite">
2426
<directory>./tests/Lib/Middleware</directory>
25-
<file>./tests/Lib/Middleware/RouterTest.php</file>
27+
<file>./tests/Lib/Middleware/RouteTest.php</file>
28+
<file>./tests/Lib/Middleware/RouterTest.php</file>
2629
</testsuite>
2730
<testsuite name="Article Test Suite">
2831
<directory>./tests/Controller</directory>
@@ -44,6 +47,10 @@
4447
<directory>./tests/Lib/Security</directory>
4548
<file>./tests/Lib/Security/HashTest.php</file>
4649
</testsuite>
50+
<testsuite name="Assert Test Suite">
51+
<directory>./tests/Lib/Assert</directory>
52+
<file>./tests/Lib/Assert/Text.php</file>
53+
</testsuite>
4754
</testsuites>
4855
<filter>
4956
<whitelist processUncoveredFilesFromWhitelist="true">

src/Lib/Command/AppPasswordCommand.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace App\Lib\Command;
34

45
use Symfony\Component\Console\Command\Command;
@@ -7,6 +8,9 @@
78
use Symfony\Component\Console\Input\InputArgument;
89
use App\Lib\Security\Hash;
910

11+
/**
12+
* @codeCoverageIgnore
13+
*/
1014
class AppPasswordCommand extends Command
1115
{
1216
/** @var string */
@@ -24,12 +28,12 @@ protected function configure()
2428
}
2529

2630
/**
27-
* Execute command
28-
*
29-
* @param InputInterface $input
30-
* @param OutputInterface $output
31-
* @return integer
32-
*/
31+
* Execute command
32+
*
33+
* @param InputInterface $input
34+
* @param OutputInterface $output
35+
* @return integer
36+
*/
3337
protected function execute(InputInterface $input, OutputInterface $output): int
3438
{
3539
$password = $input->getArgument('password');

src/Lib/Command/FixturesLoadCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace App\Lib\Command;
34

45
use Symfony\Component\Console\Command\Command;
@@ -10,6 +11,9 @@
1011
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
1112
use Doctrine\Common\DataFixtures\Loader;
1213

14+
/**
15+
* @codeCoverageIgnore
16+
*/
1317
class FixturesLoadCommand extends Command
1418
{
1519
/** @var string */
@@ -20,7 +24,7 @@ class FixturesLoadCommand extends Command
2024
*
2125
* @return void
2226
*/
23-
protected function configure():void
27+
protected function configure(): void
2428
{
2529
$this->setDescription('Loads all fixtures.')->setHelp('This command allows you to load all fixtures.');
2630
$this->addOption('yes', 'y', InputOption::VALUE_NONE, 'Continue with yes?');

src/Lib/FileSystem/File.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ public function rename(string $filename): self
262262
*/
263263
public function copy(string $destination): File
264264
{
265-
if (!copy($this->getPath(), $destination)) {
266-
throw new Exception('Failed to copy file!', 400);
267-
}
265+
copy($this->getPath(), $destination);
268266

269267
return FileSystem::open($destination);
270268
}

src/Lib/Http/Uri.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
<?php
2-
declare(strict_types = 1);
3-
namespace App\Lib\Http;
42

5-
use Exception;
3+
declare(strict_types=1);
4+
5+
namespace App\Lib\Http;
66

77
class Uri
88
{
9-
private const URL_PATH = "path";
10-
119
/**
1210
* @var array<string>
1311
*/
1412
private $path;
1513

1614
public function __construct(string $url = "")
1715
{
18-
$url = parse_url($url);
19-
if (is_array($url)) {
20-
$path = array_key_exists(self::URL_PATH, $url) ? $url[self::URL_PATH] : "";
21-
} else {
22-
throw new \Exception("Parsed URL not corespondig with required standard!");
23-
}
24-
$this->setPath($path);
16+
$path = parse_url($url, PHP_URL_PATH);
17+
$this->setPath(is_string($path) ? $path : '');
2518
}
2619

2720
/**
28-
* Sets path.
21+
* Sets path
2922
*
3023
* @param string $path
3124
* @return void
@@ -37,7 +30,7 @@ private function setPath(string $path)
3730
}
3831

3932
/**
40-
* Returns path.
33+
* Returns path
4134
*
4235
* @param boolean $original
4336
* @return array<string>

0 commit comments

Comments
 (0)