Skip to content

Commit 5dfc0a7

Browse files
Fixed all tests (#92)
1 parent 839390b commit 5dfc0a7

11 files changed

Lines changed: 117 additions & 112 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ name: build
77
jobs:
88
tests:
99
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
10-
1110
env:
1211
extensions: curl, mbstring, dom, intl, json, libxml, xml, xmlwriter
1312
key: cache-v1
14-
update: true
1513

1614
runs-on: ${{ matrix.os }}
1715

@@ -71,23 +69,19 @@ jobs:
7169
7270
- name: Install dependencies with composer php 7.4
7371
if: matrix.php-version == '7.4'
74-
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
72+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
7573

7674
- name: Install dependencies with composer php 8.0
7775
if: matrix.php-version == '8.0'
78-
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader
76+
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
7977

8078
- name: Run tests with phpunit and coverage on Linux php 7.4
8179
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
82-
run: vendor/bin/phpunit --coverage-clover=coverage.clover
83-
84-
- name: Run tests with phpunit without coverage on Linux php 8.0
85-
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '8.0'
86-
run: vendor/bin/phpunit
80+
run: vendor/bin/phpunit --coverage-clover=coverage.clover --colors=always
8781

88-
- name: Run tests with phpunit without coverage on Windows
89-
if: matrix.os == 'windows-latest'
90-
run: vendor/bin/phpunit
82+
- name: Run tests with phpunit without coverage on Windows php 7.4 - 8.0 and Linux php 7.4
83+
if: matrix.os != 'ubuntu-latest' || matrix.php-version != '7.4'
84+
run: vendor/bin/phpunit --colors=always
9185

9286
- name: Upload code coverage scrutinizer on Linux php 7.4
9387
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'

.github/workflows/static.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ name: static analysis
77
jobs:
88
mutation:
99
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
10-
1110
env:
1211
extensions: ast
13-
update: true
1412

1513
runs-on: ${{ matrix.os }}
1614

@@ -46,7 +44,7 @@ jobs:
4644
php${{ matrix.php-version }}-composer-
4745
4846
- name: Install dependencies with composer
49-
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
47+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
5048

5149
- name: Static analysis with phan
52-
run: vendor/bin/phan --no-progress-bar --output-mode checkstyle | cs2pr --graceful-warnings --colorize
50+
run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle | cs2pr --graceful-warnings --colorize

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@
3333
"phan/phan": "^3.0",
3434
"phpunit/phpunit": "^9.3",
3535
"psr/container": "1.0.0",
36+
"vimeo/psalm": "^3.15",
3637
"yiisoft/aliases": "^1.0",
3738
"yiisoft/cache": "^3.0@dev",
38-
"yiisoft/composer-config-plugin": "^1.0@dev",
3939
"yiisoft/di": "^3.0@dev",
40-
"yiisoft/event-dispatcher": "^3.0@dev",
41-
"yiisoft/log": "^3.0@dev"
40+
"yiisoft/event-dispatcher": "^3.0@dev"
4241
},
4342
"extra": {
4443
"branch-alias": {

psalm.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/PhpTemplateRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function render(View $view, string $template, array $params): string
1515

1616
$obInitialLevel = ob_get_level();
1717
ob_start();
18-
ob_implicit_flush(0);
18+
PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
1919
try {
2020
$renderer->bindTo($view)($template, $params);
2121
return ob_get_clean();

src/View.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,13 @@ public function setDynamicPlaceholders(array $placeholders): void
519519
$this->dynamicPlaceholders = $placeholders;
520520
}
521521

522-
public function addDynamicPlaceholder(string $placeholder, string $statements): void
522+
public function addDynamicPlaceholder(string $name, string $statements): void
523523
{
524524
foreach ($this->cacheStack as $cache) {
525-
$cache->addDynamicPlaceholder($placeholder, $statements);
525+
$cache->addDynamicPlaceholder($name, $statements);
526526
}
527527

528-
$this->dynamicPlaceholders[$placeholder] = $statements;
528+
$this->dynamicPlaceholders[$name] = $statements;
529529
}
530530

531531
/**
@@ -584,7 +584,7 @@ public function popDynamicContent(): void
584584
public function beginPage(): void
585585
{
586586
ob_start();
587-
ob_implicit_flush(0);
587+
PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
588588

589589
$this->eventDispatcher->dispatch(new PageBegin($this->getViewFile()));
590590
}

src/WebView.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class WebView extends View
8181
/**
8282
* @var string the page title
8383
*/
84-
private string $title;
84+
private string $title = '';
8585

8686
/**
8787
* @var array the registered meta tags.
@@ -196,7 +196,7 @@ public function renderAjax(string $view, array $params = [], ?ViewContextInterfa
196196
$viewFile = $this->findTemplateFile($view, $context);
197197

198198
ob_start();
199-
ob_implicit_flush(0);
199+
PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
200200

201201
$this->beginPage();
202202
$this->head();
@@ -542,9 +542,9 @@ protected function renderBodyEndHtml(bool $ajaxMode): string
542542
*
543543
* @return string
544544
*/
545-
public function getTitle(): ?string
545+
public function getTitle(): string
546546
{
547-
return $this->title ?? null;
547+
return $this->title;
548548
}
549549

550550
/**

tests/TestCase.php

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,45 @@
44

55
namespace Yiisoft\View\Tests;
66

7-
use Yiisoft\Composer\Config\Builder;
87
use PHPUnit\Framework\TestCase as BaseTestCase;
98
use Psr\Container\ContainerInterface;
109
use Psr\EventDispatcher\EventDispatcherInterface;
1110
use Psr\EventDispatcher\ListenerProviderInterface;
1211
use Psr\Log\LoggerInterface;
12+
use Psr\Log\NullLogger;
1313
use Yiisoft\Aliases\Aliases;
1414
use Yiisoft\Di\Container;
15+
use Yiisoft\Factory\Definitions\Reference;
16+
use Yiisoft\EventDispatcher\Dispatcher\Dispatcher;
17+
use Yiisoft\EventDispatcher\Provider\Provider;
1518
use Yiisoft\Files\FileHelper;
1619
use Yiisoft\View\Theme;
1720
use Yiisoft\View\View;
1821
use Yiisoft\View\WebView;
22+
use Yiisoft\View\Tests\Mocks\WebViewPlaceholderMock;
23+
24+
use function str_replace;
1925

2026
abstract class TestCase extends BaseTestCase
2127
{
22-
/**
23-
* @var Aliases $aliases
24-
*/
25-
protected $aliases;
26-
27-
/**
28-
* @var ContainerInterface $container
29-
*/
30-
private $container;
31-
32-
/**
33-
* @var EventDispatcherInterface $eventDispatcher
34-
*/
35-
protected $eventDispatcher;
36-
37-
/**
38-
* @var LoggerInterface $logger
39-
*/
40-
protected $logger;
41-
42-
/**
43-
* @var Theme $theme
44-
*/
45-
protected $theme;
28+
private ContainerInterface $container;
29+
private EventDispatcherInterface $eventDispatcher;
30+
private LoggerInterface $logger;
31+
protected Aliases $aliases;
32+
protected WebView $webView;
33+
protected WebViewPlaceholderMock $webViewPlaceholderMock;
4634

47-
/**
48-
* @var WebView $webView
49-
*/
50-
protected $webView;
51-
52-
/**
53-
* @var ListenerProviderInterface
54-
*/
55-
protected $listenerProvider;
56-
57-
/**
58-
* setUp
59-
*
60-
* @return void
61-
*/
6235
protected function setUp(): void
6336
{
6437
parent::setUp();
6538

66-
$config = require Builder::path('tests');
67-
68-
$this->container = new Container($config);
39+
$this->container = new Container($this->config());
6940

7041
$this->aliases = $this->container->get(Aliases::class);
7142
$this->eventDispatcher = $this->container->get(EventDispatcherInterface::class);
72-
$this->listenerProvider = $this->container->get(ListenerProviderInterface::class);
7343
$this->logger = $this->container->get(LoggerInterface::class);
7444
$this->webView = $this->container->get(WebView::class);
45+
$this->webViewPlaceholderMock = $this->container->get(WebViewPlaceholderMock::class);
7546
}
7647

7748
protected function getContainer(): ContainerInterface
@@ -86,7 +57,7 @@ protected function getContainer(): ContainerInterface
8657
*/
8758
protected function tearDown(): void
8859
{
89-
$this->container = null;
60+
unset($this->container, );
9061
parent::tearDown();
9162
}
9263

@@ -125,11 +96,11 @@ protected function assertSameIgnoringSlash(string $expected, string $actual): vo
12596
* Create view tests.
12697
*
12798
* @param string $basePath
128-
* @param Theme $theme
99+
* @param Theme|null $theme
129100
*
130101
* @return View
131102
*/
132-
protected function createView($basePath, Theme $theme = null): View
103+
protected function createView(string $basePath, ?Theme $theme = null): View
133104
{
134105
return new View($basePath, $theme ?: new Theme(), $this->eventDispatcher, $this->logger);
135106
}
@@ -140,4 +111,55 @@ protected function touch(string $path): void
140111

141112
touch($path);
142113
}
114+
115+
private function config(): array
116+
{
117+
return [
118+
Aliases::class => [
119+
'__class' => Aliases::class,
120+
'__construct()' => [
121+
[
122+
'@root' => __DIR__,
123+
'@baseUrl' => '/baseUrl'
124+
]
125+
]
126+
],
127+
128+
LoggerInterface::class => NullLogger::class,
129+
130+
ListenerProviderInterface::class => Provider::class,
131+
132+
EventDispatcherInterface::class => Dispatcher::class,
133+
134+
View::class => [
135+
'__class' => View::class,
136+
'__construct()' => [
137+
__DIR__ . '/public/view',
138+
Reference::to(Theme::class),
139+
Reference::to(EventDispatcherInterface::class),
140+
Reference::to(LoggerInterface::class)
141+
]
142+
],
143+
144+
WebView::class => [
145+
'__class' => WebView::class,
146+
'__construct()' => [
147+
__DIR__ . '/public/view',
148+
Reference::to(Theme::class),
149+
Reference::to(EventDispatcherInterface::class),
150+
Reference::to(LoggerInterface::class)
151+
]
152+
],
153+
154+
WebViewPlaceholderMock::class => [
155+
'__class' => WebViewPlaceholderMock::class,
156+
'__construct()' => [
157+
__DIR__ . '/public/view',
158+
Reference::to(Theme::class),
159+
Reference::to(EventDispatcherInterface::class),
160+
Reference::to(LoggerInterface::class)
161+
]
162+
]
163+
];
164+
}
143165
}

tests/ThemeTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
/**
1111
* ThemeTest.
1212
*/
13-
final class ThemeTest extends \Yiisoft\View\Tests\TestCase
13+
final class ThemeTest extends TestCase
1414
{
15-
/**
16-
* @var string path for the test files.
17-
*/
18-
protected $testViewPath;
15+
protected string $testViewPath;
1916

2017
public function setUp(): void
2118
{

0 commit comments

Comments
 (0)