Skip to content

Commit d8e8408

Browse files
committed
test: ajout de test pour PhpIniCheck
1 parent 104355a commit d8e8408

3 files changed

Lines changed: 116 additions & 1 deletion

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Blitz PHP framework.
5+
*
6+
* (c) 2022 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
use BlitzPHP\Spec\CliOutputHelper as COH;
13+
14+
use function Kahlan\expect;
15+
16+
describe('Commandes / PhpIniCheck', function (): void {
17+
beforeEach(function (): void {
18+
COH::setUp();
19+
});
20+
21+
afterEach(function (): void {
22+
COH::tearDown();
23+
});
24+
25+
beforeAll(function (): void {
26+
COH::setUpBeforeClass();
27+
});
28+
29+
afterAll(function (): void {
30+
COH::tearDownAfterClass();
31+
});
32+
33+
it('phpini:check', function (): void {
34+
command('phpini:check');
35+
36+
$result = COH::buffer();
37+
38+
expect($result)->toMatch(static fn ($actual) => str_contains($actual, 'Directive'));
39+
expect($result)->toMatch(static fn ($actual) => str_contains($actual, 'Globale'));
40+
expect($result)->toMatch(static fn ($actual) => str_contains($actual, 'Actuelle'));
41+
expect($result)->toMatch(static fn ($actual) => str_contains($actual, 'Recommandation'));
42+
expect($result)->toMatch(static fn ($actual) => str_contains($actual, 'Remarque'));
43+
});
44+
45+
it('phpini:check opcache', function (): void {
46+
command('phpini:check opcache');
47+
48+
expect(COH::buffer())->toMatch(static fn ($actual) => str_contains($actual, 'opcache.save_comments'));
49+
});
50+
51+
it('phpini:check avec un argument non valide', function (): void {
52+
command('phpini:check unknown');
53+
54+
expect(COH::buffer())->toMatch(static fn ($actual) => str_contains($actual, 'Vous devez indiquer un argument correct.'));
55+
});
56+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Blitz PHP framework.
5+
*
6+
* (c) 2022 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
use BlitzPHP\Security\CheckPhpIni;
13+
14+
use function Kahlan\expect;
15+
16+
describe('Security / CheckPhpIni', function (): void {
17+
beforeAll(function(): void {
18+
$ini = ini_get_all();
19+
20+
$this->display_errors = $ini['display_errors'] ?? ['global_value' => 'disabled', 'local_value' => 'disabled'];
21+
$this->opcache = $ini['opcache'] ?? ['global_value' => 'disabled', 'local_value' => 'disabled'];
22+
});
23+
24+
it('Check ini', function (): void {
25+
$output = CheckPhpIni::checkIni();
26+
27+
expect($output['display_errors'])->toBe([
28+
'global' => $this->display_errors['global_value'],
29+
'current' => $this->display_errors['local_value'],
30+
'recommended' => '0',
31+
'remark' => '',
32+
]);
33+
});
34+
35+
it('Check opcache', function (): void {
36+
$output = CheckPhpIni::checkIni('opcache');
37+
38+
expect($output['opcache.save_comments'])->toBe([
39+
'global' => $this->opcache['global_value'],
40+
'current' => $this->opcache['local_value'],
41+
'recommended' => '0',
42+
'remark' => 'Activé lorsque vous utilisez l\'annotation docblock `package require`',
43+
]);
44+
});
45+
46+
it('Run web', function (): void {
47+
$output = CheckPhpIni::run(false);
48+
49+
$expected = [
50+
'global' => '1',
51+
'current' => '1',
52+
'recommended' => '0',
53+
'remark' => 'Enable when you using package require docblock annotation',
54+
];
55+
56+
expect($output)->toBeA('string');
57+
// expect(str_contains($output, 'display_errors'))->toBeTruthy();
58+
});
59+
});

src/Cli/Commands/Utilities/PhpIniCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class PhpIniCheck extends Command
4646
public function execute(array $params)
4747
{
4848
unset($params['help'], $params['version'], $params['verbosity']);
49-
$params = array_values($params);
49+
$params = array_values(array_filter($params));
5050

5151
if (isset($params[0]) && ! in_array($params[0], array_keys($this->arguments), true)) {
5252
$this->fail('Vous devez indiquer un argument correct.')->eol();

0 commit comments

Comments
 (0)