Skip to content

Commit 025749d

Browse files
committed
Updated test case
1 parent 22f876f commit 025749d

5 files changed

Lines changed: 66 additions & 60 deletions

File tree

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
}
3838
},
3939
"autoload-dev": {
40-
"files": [
41-
"tests/stubs/constants.php"
42-
],
4340
"psr-4": {
4441
"MobicmsTest\\Stubs\\": "tests/stubs/src"
4542
}

composer.lock

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

tests/Pest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
const DS = DIRECTORY_SEPARATOR;
6+
const M_PATH_ROOT = __DIR__ . DS . 'stubs' . DS . 'templates' . DS;

tests/stubs/constants.php

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

tests/unit/EngineTest.php

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,41 @@
1414
expect($engine->getFileExtension())->toBe('phtml');
1515
});
1616

17-
test('Let\'s try to add and then get several folders', function () use ($engine) {
18-
$engine->addPath('folder1', 'ns1')
19-
->addPath('folder2', 'ns1')
20-
->addPath(M_PATH_ROOT);
21-
expect($engine->getPath('ns1'))->toContain('folder1')
22-
->and($engine->getPath('ns1'))->toContain('folder2')
23-
->and($engine->getPath('main'))->toContain(rtrim(M_PATH_ROOT, '/\\'));
24-
});
17+
describe('addPath()', function () {
18+
$engine = new Engine();
19+
20+
test('let\'s try to add and then get several folders', function () use ($engine) {
21+
$engine->addPath('folder1', 'ns1')
22+
->addPath('folder2', 'ns1')
23+
->addPath(M_PATH_ROOT);
24+
expect($engine->getPath('ns1'))->toContain('folder1')
25+
->and($engine->getPath('ns1'))->toContain('folder2')
26+
->and($engine->getPath('main'))->toContain(rtrim(M_PATH_ROOT, '/\\'));
27+
});
28+
29+
it('throws an exception on adding a folder with an empty namespace', function () use ($engine) {
30+
$engine->addPath('folder', '');
31+
})->throws(InvalidArgumentException::class, 'Namespace cannot be empty.');
2532

26-
test('Ability to pass data to a template', function () use ($engine) {
27-
// Share data with all templates
28-
$engine->addData(['all' => 'AllTemplatesData']);
33+
it('throws an exception on adding a folder with an empty path', function () use ($engine) {
34+
$engine->addPath('');
35+
})->throws(InvalidArgumentException::class, 'You must specify folder.');
36+
});
2937

30-
// Passing data to a specific template
31-
$engine->addData(['tpl1' => 'Tpl1Data'], ['template1']);
32-
$engine->addData(['tpl2' => 'Tpl2Data'], ['template2']);
38+
describe('addData()', function () {
39+
$engine = new Engine();
3340

34-
expect($engine->getTemplateData()['all'])->toBe('AllTemplatesData')
35-
->and($engine->getTemplateData('template1')['tpl1'])->toBe('Tpl1Data')
36-
->and($engine->getTemplateData('template2')['tpl2'])->toBe('Tpl2Data');
41+
test('share data with all templates', function () use ($engine) {
42+
$engine->addData(['all' => 'AllTemplatesData']);
43+
expect($engine->getTemplateData()['all'])->toBe('AllTemplatesData');
44+
});
45+
46+
test('passing data to a specific template', function () use ($engine) {
47+
$engine->addData(['tpl1' => 'Tpl1Data'], ['template1']);
48+
$engine->addData(['tpl2' => 'Tpl2Data'], ['template2']);
49+
expect($engine->getTemplateData('template1')['tpl1'])->toBe('Tpl1Data')
50+
->and($engine->getTemplateData('template2')['tpl2'])->toBe('Tpl2Data');
51+
});
3752
});
3853

3954
test('Can render template', function () use ($engine) {
@@ -71,14 +86,6 @@
7186
describe('Exception handling:', function () {
7287
$engine = new Engine();
7388

74-
test('adding a folder with an empty namespace', function () use ($engine) {
75-
$engine->addPath('folder', '');
76-
})->throws(InvalidArgumentException::class, 'Namespace cannot be empty.');
77-
78-
test('adding a folder with an empty path', function () use ($engine) {
79-
$engine->addPath('');
80-
})->throws(InvalidArgumentException::class, 'You must specify folder.');
81-
8289
test('accessing a nonexistent namespace', function () use ($engine) {
8390
$engine->getPath('name');
8491
})->throws(InvalidArgumentException::class, 'The template namespace "name" was not found.');

0 commit comments

Comments
 (0)