Skip to content

Commit aacf196

Browse files
author
Jean-François Lépine
committed
improved tests
1 parent d42b322 commit aacf196

File tree

6 files changed

+115
-4
lines changed

6 files changed

+115
-4
lines changed

src/Toolkit/phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@
2222
<listeners>
2323
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
2424
</listeners>
25+
<coverage>
26+
<include>
27+
<directory suffix=".php">src</directory>
28+
</include>
29+
</coverage>
2530
</phpunit>

src/Toolkit/src/Registry/DependenciesResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function resolve(Registry $registry): array
2424
$unresolved = [];
2525

2626
$concernedComponents = [];
27-
foreach($registry->all() as $item) {
28-
if ($item->type !== RegistryItemType::Component) {
27+
foreach ($registry->all() as $item) {
28+
if (RegistryItemType::Component !== $item->type) {
2929
continue;
3030
}
3131

src/Toolkit/src/Registry/RegistryItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static function fromTwigFile(SplFileInfo $file): self
8383
if ($name === $parentName) {
8484
$parentName = null;
8585
}
86-
// @todo: we should improve the way to detect examples
86+
// @todo: we should improve the way we detect examples
8787
$isExample = preg_match('#examples#', $file->getRelativePathname());
8888
$type = $isExample ? RegistryItemType::Example : RegistryItemType::Component;
8989
$theme = '';

src/Toolkit/tests/Command/UxToolkitInstallCommandTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Symfony\UX\Toolkit\Tests\Command;
1313

14-
use PHPUnit\Framework\TestCase;
1514
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
1615
use Zenstruck\Console\Test\InteractsWithConsole;
1716

1817
/**
1918
* @author Jean-François Lépine
19+
*
2020
* @group wip
2121
*/
2222
class UxToolkitInstallCommandTest extends KernelTestCase
@@ -43,4 +43,32 @@ public function testShouldAbleToCreateTheBadgeComponent(): void
4343
$actualContent = file_get_contents($expectedFile);
4444
$this->assertEquals($expectedContent, $actualContent);
4545
}
46+
47+
public function testShouldFailWhenComponentDoesNotExist(): void
48+
{
49+
$destination = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid();
50+
mkdir($destination);
51+
52+
$this->bootKernel();
53+
$this->consoleCommand('ux:toolkit:install unknown --destination='.$destination)
54+
->execute()
55+
->assertFaulty()
56+
->assertOutputContains('The component "Unknown" does not exist.');
57+
}
58+
59+
public function testShouldFailWhenComponentFileAlreadyExistsInNonInteractiveMode(): void
60+
{
61+
$destination = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid();
62+
mkdir($destination);
63+
64+
$this->bootKernel();
65+
$this->consoleCommand('ux:toolkit:install badge --destination='.$destination)
66+
->execute()
67+
->assertSuccessful();
68+
69+
$this->consoleCommand('ux:toolkit:install badge --destination='.$destination)
70+
->execute()
71+
->assertFaulty()
72+
->assertOutputContains('The component "Badge" already exists.');
73+
}
4674
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\Toolkit\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\UX\Toolkit\DependencyInjection\ToolkitExtension;
17+
18+
/**
19+
* @author Jean-François Lépine
20+
*/
21+
class ToolkitExtensionTest extends TestCase
22+
{
23+
public function testGetAlias(): void
24+
{
25+
$extension = new ToolkitExtension();
26+
$this->assertEquals('ux_toolkit', $extension->getAlias());
27+
}
28+
29+
public function testLoadInjectUsefulParameters(): void
30+
{
31+
$configs = [
32+
'prefix' => 'Acme',
33+
'theme' => 'default',
34+
];
35+
36+
$container = new ContainerBuilder();
37+
$extension = new ToolkitExtension();
38+
$extension->load([$configs], $container);
39+
40+
$this->assertTrue($container->hasParameter('ux_toolkit.prefix'));
41+
$this->assertEquals('Acme', $container->getParameter('ux_toolkit.prefix'));
42+
43+
$this->assertTrue($container->hasParameter('ux_toolkit.theme'));
44+
$this->assertEquals('default', $container->getParameter('ux_toolkit.theme'));
45+
}
46+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\Toolkit\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\UX\Toolkit\DependencyInjection\ToolkitExtension;
18+
use Symfony\UX\Toolkit\UxToolkitBundle;
19+
20+
/**
21+
* @author Jean-François Lépine
22+
*/
23+
class UxToolkitBundleTest extends KernelTestCase
24+
{
25+
public function testBundleBuildsSuccessfully(): void
26+
{
27+
self::bootKernel();
28+
$container = self::$kernel->getContainer();
29+
30+
$this->assertInstanceOf(UxToolkitBundle::class, $container->get('kernel')->getBundles()['UxToolkitBundle']);
31+
}
32+
}

0 commit comments

Comments
 (0)