Skip to content

Commit d17c82e

Browse files
committed
Init test running the code of README in install first chapter
1 parent a0a7211 commit d17c82e

3 files changed

Lines changed: 42 additions & 4 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ Enable it globally:
1313
\Phug\Component\ComponentExtension::enable();
1414
```
1515

16+
To enable it automatically when calling static methods `render`, `renderFile`,
17+
`display`, `displayFile` etc. on either `\Pug\Facade` or `\Phug\Phug` class.
18+
19+
If using in a `\Pug\Pug` or `\Phug\Renderer` instance, add the `ComponentExtension`
20+
class to modules:
21+
```php
22+
$pug = new \Pug\Pug([
23+
'modules' => [\Phug\Component\ComponentExtension::class],
24+
]);
25+
```
26+
1627
## Usage
1728

1829
```pug

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
"minimum-stability": "stable",
2222
"require": {
2323
"php": ">=7.2",
24-
"phug/renderer": "^1.3"
24+
"phug/phug": "^1.3"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^8"
27+
"phpunit/phpunit": "^8",
28+
"pug-php/pug": "^3"
2829
},
2930
"autoload": {
3031
"psr-4": {

tests/Phug/Component/ComponentExtensionTest.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,40 @@
33
namespace Phug\Test\Component;
44

55
use PHPUnit\Framework\TestCase;
6+
use Phug\Phug;
67

78
class ComponentExtensionTest extends TestCase
89
{
10+
/**
11+
* @var string
12+
*/
13+
protected $readme = null;
14+
15+
protected function getReadmeContents(): string
16+
{
17+
if ($this->readme === null) {
18+
$this->readme = file_get_contents(__DIR__ . '/../../../README.md');
19+
}
20+
21+
return $this->readme;
22+
}
23+
24+
protected function setUp(): void
25+
{
26+
preg_match(
27+
'/```php\n(?<php>[\s\S]+)\n```/U',
28+
$this->getReadmeContents(),
29+
$install
30+
);
31+
32+
eval($install['php']);
33+
}
34+
935
public function getReadmeExamples()
1036
{
1137
preg_match_all(
1238
'/```pug\n(?<pug>[\s\S]+)\n```[\s\S]*```html\n(?<html>[\s\S]+)\n```/U',
13-
file_get_contents(__DIR__.'/../../../README.md'),
39+
$this->getReadmeContents(),
1440
$examples,
1541
PREG_SET_ORDER
1642
);
@@ -25,6 +51,6 @@ public function getReadmeExamples()
2551
*/
2652
public function testReadme($htmlCode, $pugCode)
2753
{
28-
$this->assertSame($htmlCode, $pugCode);
54+
$this->assertSame($htmlCode, Phug::render($pugCode));
2955
}
3056
}

0 commit comments

Comments
 (0)