Skip to content

Commit 75498e5

Browse files
committed
Created the BDD DSL
1 parent a57c14f commit 75498e5

28 files changed

+310
-148
lines changed

bin/pyramidal

-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ if (! file_exists($autoloadFileName)) {
99
}
1010

1111
require_once $autoloadFileName;
12-
require_once __DIR__.'/../src/DSL/TDD/TDD.php';
1312

1413
\ThenLabs\PyramidalTests\Framework::main();

bootstrap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
declare(strict_types=1);
33

44
require_once __DIR__.'/vendor/autoload.php';
5-
require_once __DIR__.'/src/DSL/TDD/TDD.php';
5+
require_once __DIR__.'/src/DSL/TDD.php';
66

77
define('ROOT_DIR', __DIR__);
88

src/DSL/BDD.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use ThenLabs\PyramidalTests\Decorator\DecoratorsRegistry;
5+
use ThenLabs\PyramidalTests\DSL\Decorator\EndTestCaseDecorator;
6+
use ThenLabs\PyramidalTests\DSL\Decorator\SetUpBeforeClassDecorator;
7+
use ThenLabs\PyramidalTests\DSL\Decorator\SetUpBeforeClassOnceDecorator;
8+
use ThenLabs\PyramidalTests\DSL\Decorator\SetUpDecorator;
9+
use ThenLabs\PyramidalTests\DSL\Decorator\TearDownAfterClassDecorator;
10+
use ThenLabs\PyramidalTests\DSL\Decorator\TearDownAfterClassOnceDecorator;
11+
use ThenLabs\PyramidalTests\DSL\Decorator\TearDownDecorator;
12+
use ThenLabs\PyramidalTests\DSL\Decorator\TestCaseDecorator;
13+
use ThenLabs\PyramidalTests\DSL\Decorator\TestDecorator;
14+
use ThenLabs\PyramidalTests\DSL\DSL;
15+
use ThenLabs\PyramidalTests\Model\TestCaseModel;
16+
use ThenLabs\PyramidalTests\Model\TestModel;
17+
18+
require_once __DIR__.'/Common.php';
19+
20+
DecoratorsRegistry::registerGlobal('describe', new TestCaseDecorator());
21+
DecoratorsRegistry::registerGlobal('end', new EndTestCaseDecorator());
22+
DecoratorsRegistry::registerGlobal('beforeAll', new SetUpBeforeClassDecorator());
23+
DecoratorsRegistry::registerGlobal('beforeAllOnce', new SetUpBeforeClassOnceDecorator());
24+
DecoratorsRegistry::registerGlobal('beforeEach', new SetUpDecorator());
25+
DecoratorsRegistry::registerGlobal('it', new TestDecorator());
26+
DecoratorsRegistry::registerGlobal('afterEach', new TearDownDecorator());
27+
DecoratorsRegistry::registerGlobal('afterAll', new TearDownAfterClassDecorator());
28+
DecoratorsRegistry::registerGlobal('afterAllOnce', new TearDownAfterClassOnceDecorator());
29+
30+
function describe($firstArgument = '', Closure $secondArgument = null): TestCaseModel
31+
{
32+
return DSL::testCase($firstArgument, $secondArgument);
33+
}
34+
35+
function beforeAll(Closure $closure, bool $invokeParents = true): void
36+
{
37+
DSL::setUpBeforeClass($closure, $invokeParents);
38+
}
39+
40+
function beforeAllOnce(Closure $closure, bool $invokeParents = true): void
41+
{
42+
DSL::setUpBeforeClassOnce($closure, $invokeParents);
43+
}
44+
45+
function beforeEach(Closure $closure, bool $invokeParents = true): void
46+
{
47+
DSL::setUp($closure, $invokeParents);
48+
}
49+
50+
/**
51+
* @param string|Closure
52+
* @param Closure|null
53+
*/
54+
function it($firstArgument, Closure $secondArgument = null): TestModel
55+
{
56+
return DSL::test($firstArgument, $secondArgument);
57+
}
58+
59+
function afterEach(Closure $closure, bool $invokeParents = true): void
60+
{
61+
DSL::tearDown($closure, $invokeParents);
62+
}
63+
64+
function afterAll(Closure $closure, bool $invokeParents = true): void
65+
{
66+
DSL::tearDownAfterClass($closure, $invokeParents);
67+
}
68+
69+
function afterAllOnce(Closure $closure, bool $invokeParents = true): void
70+
{
71+
DSL::tearDownAfterClassOnce($closure, $invokeParents);
72+
}

src/DSL/Common.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use ThenLabs\PyramidalTests\Decorator\DecoratorsRegistry;
5+
use ThenLabs\PyramidalTests\DSL\Decorator\MethodDecorator;
6+
use ThenLabs\PyramidalTests\DSL\Decorator\PropertyDecorator;
7+
use ThenLabs\PyramidalTests\DSL\Decorator\StaticMethodDecorator;
8+
use ThenLabs\PyramidalTests\DSL\Decorator\StaticPropertyDecorator;
9+
use ThenLabs\PyramidalTests\DSL\Decorator\UseMacroDecorator;
10+
use ThenLabs\PyramidalTests\DSL\Decorator\UseTraitDecorator;
11+
use ThenLabs\PyramidalTests\DSL\DSL;
12+
use ThenLabs\PyramidalTests\Utils\Proxy;
13+
14+
DecoratorsRegistry::registerGlobal('staticProperty', new StaticPropertyDecorator());
15+
DecoratorsRegistry::registerGlobal('property', new PropertyDecorator());
16+
DecoratorsRegistry::registerGlobal('staticMethod', new StaticMethodDecorator());
17+
DecoratorsRegistry::registerGlobal('method', new MethodDecorator());
18+
DecoratorsRegistry::registerGlobal('useMacro', new UseMacroDecorator());
19+
DecoratorsRegistry::registerGlobal('useTrait', new UseTraitDecorator());
20+
21+
function setTestCaseClass(string $testCaseClass): void
22+
{
23+
DSL::setTestCaseClass($testCaseClass);
24+
}
25+
26+
function macro(string $title, Closure $closure): void
27+
{
28+
DSL::macro($title, $closure);
29+
}
30+
31+
function useMacro(string $title): void
32+
{
33+
DSL::useMacro($title);
34+
}
35+
36+
function useAndExtendMacro(string $title, Closure $closure): void
37+
{
38+
DSL::useMacro($title, $closure);
39+
}
40+
41+
function staticProperty(string $name, $value = null): Proxy
42+
{
43+
return DSL::staticProperty($name, $value);
44+
}
45+
46+
function property(string $name, $value = null): Proxy
47+
{
48+
return DSL::property($name, $value);
49+
}
50+
51+
function staticMethod(string $name, Closure $closure): Proxy
52+
{
53+
return DSL::staticMethod($name, $closure);
54+
}
55+
56+
function method(string $name, Closure $closure): Proxy
57+
{
58+
return DSL::method($name, $closure);
59+
}
60+
61+
function useTrait(string $trait, array $definitions = []): void
62+
{
63+
DSL::useTrait($trait, $definitions);
64+
}

src/DSL/TDD/Decorator/EndTestCaseDecorator.php src/DSL/Decorator/EndTestCaseDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\Model\TestCaseModel;

src/DSL/TDD/Decorator/MethodDecorator.php src/DSL/Decorator/MethodDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/PropertyDecorator.php src/DSL/Decorator/PropertyDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/SetUpBeforeClassDecorator.php src/DSL/Decorator/SetUpBeforeClassDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/SetUpBeforeClassOnceDecorator.php src/DSL/Decorator/SetUpBeforeClassOnceDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/SetUpDecorator.php src/DSL/Decorator/SetUpDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/StaticMethodDecorator.php src/DSL/Decorator/StaticMethodDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/StaticPropertyDecorator.php src/DSL/Decorator/StaticPropertyDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/TearDownAfterClassDecorator.php src/DSL/Decorator/TearDownAfterClassDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/TearDownAfterClassOnceDecorator.php src/DSL/Decorator/TearDownAfterClassOnceDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/TearDownDecorator.php src/DSL/Decorator/TearDownDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/TestCaseDecorator.php src/DSL/Decorator/TestCaseDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/TestDecorator.php src/DSL/Decorator/TestDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/UseMacroDecorator.php src/DSL/Decorator/UseMacroDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD/Decorator/UseTraitDecorator.php src/DSL/Decorator/UseTraitDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ThenLabs\PyramidalTests\DSL\TDD\Decorator;
4+
namespace ThenLabs\PyramidalTests\DSL\Decorator;
55

66
use ThenLabs\PyramidalTests\Decorator\AbstractDecorator;
77
use ThenLabs\PyramidalTests\DSL\DSL;

src/DSL/TDD.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use ThenLabs\PyramidalTests\Decorator\DecoratorsRegistry;
5+
use ThenLabs\PyramidalTests\DSL\Decorator\EndTestCaseDecorator;
6+
use ThenLabs\PyramidalTests\DSL\Decorator\SetUpBeforeClassDecorator;
7+
use ThenLabs\PyramidalTests\DSL\Decorator\SetUpBeforeClassOnceDecorator;
8+
use ThenLabs\PyramidalTests\DSL\Decorator\SetUpDecorator;
9+
use ThenLabs\PyramidalTests\DSL\Decorator\TearDownAfterClassDecorator;
10+
use ThenLabs\PyramidalTests\DSL\Decorator\TearDownAfterClassOnceDecorator;
11+
use ThenLabs\PyramidalTests\DSL\Decorator\TearDownDecorator;
12+
use ThenLabs\PyramidalTests\DSL\Decorator\TestCaseDecorator;
13+
use ThenLabs\PyramidalTests\DSL\Decorator\TestDecorator;
14+
use ThenLabs\PyramidalTests\DSL\DSL;
15+
use ThenLabs\PyramidalTests\Model\TestCaseModel;
16+
use ThenLabs\PyramidalTests\Model\TestModel;
17+
18+
require_once __DIR__.'/Common.php';
19+
20+
DecoratorsRegistry::registerGlobal('testCase', new TestCaseDecorator());
21+
DecoratorsRegistry::registerGlobal('endTestCase', new EndTestCaseDecorator());
22+
DecoratorsRegistry::registerGlobal('setUpBeforeClass', new SetUpBeforeClassDecorator());
23+
DecoratorsRegistry::registerGlobal('setUpBeforeClassOnce', new SetUpBeforeClassOnceDecorator());
24+
DecoratorsRegistry::registerGlobal('setUp', new SetUpDecorator());
25+
DecoratorsRegistry::registerGlobal('test', new TestDecorator());
26+
DecoratorsRegistry::registerGlobal('tearDown', new TearDownDecorator());
27+
DecoratorsRegistry::registerGlobal('tearDownAfterClass', new TearDownAfterClassDecorator());
28+
DecoratorsRegistry::registerGlobal('tearDownAfterClassOnce', new TearDownAfterClassOnceDecorator());
29+
30+
function testCase($firstArgument = '', Closure $secondArgument = null): TestCaseModel
31+
{
32+
return DSL::testCase($firstArgument, $secondArgument);
33+
}
34+
35+
function setUpBeforeClass(Closure $closure, bool $invokeParents = true): void
36+
{
37+
DSL::setUpBeforeClass($closure, $invokeParents);
38+
}
39+
40+
function setUpBeforeClassOnce(Closure $closure, bool $invokeParents = true): void
41+
{
42+
DSL::setUpBeforeClassOnce($closure, $invokeParents);
43+
}
44+
45+
function setUp(Closure $closure, bool $invokeParents = true): void
46+
{
47+
DSL::setUp($closure, $invokeParents);
48+
}
49+
50+
/**
51+
* @param string|Closure
52+
* @param Closure|null
53+
*/
54+
function test($firstArgument, Closure $secondArgument = null): TestModel
55+
{
56+
return DSL::test($firstArgument, $secondArgument);
57+
}
58+
59+
function tearDown(Closure $closure, bool $invokeParents = true): void
60+
{
61+
DSL::tearDown($closure, $invokeParents);
62+
}
63+
64+
function tearDownAfterClass(Closure $closure, bool $invokeParents = true): void
65+
{
66+
DSL::tearDownAfterClass($closure, $invokeParents);
67+
}
68+
69+
function tearDownAfterClassOnce(Closure $closure, bool $invokeParents = true): void
70+
{
71+
DSL::tearDownAfterClassOnce($closure, $invokeParents);
72+
}

0 commit comments

Comments
 (0)