Skip to content

Commit 95f7276

Browse files
committed
iterate
1 parent 7cafae4 commit 95f7276

File tree

8 files changed

+506
-0
lines changed

8 files changed

+506
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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\Dependency;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\UX\Toolkit\Dependency\RecipeDependency;
16+
17+
final class RecipeDependencyTest extends TestCase
18+
{
19+
public function testShouldBeInstantiable()
20+
{
21+
$dependency = new RecipeDependency('Table');
22+
$this->assertSame('Table', $dependency->name);
23+
$this->assertSame('Recipe "Table"', (string) $dependency);
24+
}
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "../../../../../schema-kit-recipe-v1.json",
3+
"type": "component",
4+
"name": "C",
5+
"description": "Component C",
6+
"copy-files": {
7+
"templates/": "templates/"
8+
},
9+
"dependencies": [
10+
{
11+
"type": "recipe",
12+
"name": "A"
13+
}
14+
]
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% props render_child = false %}
2+
{% if render_child %}
3+
<twig:A />
4+
{% endif %}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\UX\Toolkit\Tests\Kit;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\UX\Toolkit\Kit\KitManifest;
9+
10+
final class KitManifestTest extends TestCase
11+
{
12+
public function testFromJsonWithInvalidJson()
13+
{
14+
$this->expectException(\JsonException::class);
15+
$this->expectExceptionMessage('Syntax error');
16+
17+
KitManifest::fromJson('test');
18+
}
19+
20+
public function testFromJsonWithEmpty()
21+
{
22+
$this->expectException(\InvalidArgumentException::class);
23+
$this->expectExceptionMessage('Property "name" is required.');
24+
25+
KitManifest::fromJson('{}');
26+
}
27+
28+
public function testFromJsonWithMissingDescription()
29+
{
30+
$this->expectException(\InvalidArgumentException::class);
31+
$this->expectExceptionMessage('Property "description" is required.');
32+
33+
KitManifest::fromJson(<<<JSON
34+
{
35+
"name": "kit"
36+
}
37+
JSON);
38+
}
39+
40+
public function testFromJsonWithMissingLicense()
41+
{
42+
$this->expectException(\InvalidArgumentException::class);
43+
$this->expectExceptionMessage('Property "license" is required.');
44+
45+
KitManifest::fromJson(<<<JSON
46+
{
47+
"name": "kit",
48+
"description": "A kit"
49+
}
50+
JSON);
51+
}
52+
53+
public function testFromJsonWithMissingHomepage()
54+
{
55+
$this->expectException(\InvalidArgumentException::class);
56+
$this->expectExceptionMessage('Property "homepage" is required.');
57+
58+
KitManifest::fromJson(<<<JSON
59+
{
60+
"name": "kit",
61+
"description": "A kit",
62+
"license": "MIT"
63+
}
64+
JSON);
65+
}
66+
67+
public function testFromJsonWithInvalidHomepage()
68+
{
69+
$this->expectException(\InvalidArgumentException::class);
70+
$this->expectExceptionMessage('Invalid homepage URL "not-a-url".');
71+
72+
KitManifest::fromJson(<<<JSON
73+
{
74+
"name": "kit",
75+
"description": "A kit",
76+
"license": "MIT",
77+
"homepage": "not-a-url"
78+
}
79+
JSON);
80+
}
81+
82+
public function testFromJsonWithValidData()
83+
{
84+
$manifest = KitManifest::fromJson(<<<JSON
85+
{
86+
"name": "kit",
87+
"description": "A kit",
88+
"license": "MIT",
89+
"homepage": "https://example.com"
90+
}
91+
JSON);
92+
93+
$this->assertSame('kit', $manifest->name);
94+
$this->assertSame('A kit', $manifest->description);
95+
$this->assertSame('MIT', $manifest->license);
96+
$this->assertSame('https://example.com', $manifest->homepage);
97+
}
98+
}
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\UX\Toolkit\Tests\Recipe;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\UX\Toolkit\Dependency\PhpPackageDependency;
9+
use Symfony\UX\Toolkit\Dependency\RecipeDependency;
10+
use Symfony\UX\Toolkit\Dependency\Version;
11+
use Symfony\UX\Toolkit\Recipe\RecipeManifest;
12+
use Symfony\UX\Toolkit\Recipe\RecipeType;
13+
14+
final class RecipeManifestTest extends TestCase
15+
{
16+
public function testFromJsonWithInvalidJson()
17+
{
18+
$this->expectException(\JsonException::class);
19+
$this->expectExceptionMessage('Syntax error');
20+
21+
RecipeManifest::fromJson('test');
22+
}
23+
24+
public function testFromJsonWithEmpty()
25+
{
26+
$this->expectException(\InvalidArgumentException::class);
27+
$this->expectExceptionMessage('Property "type" is required.');
28+
29+
RecipeManifest::fromJson('{}');
30+
}
31+
32+
public function testFromJsonWithInvalidType()
33+
{
34+
$this->expectException(\InvalidArgumentException::class);
35+
$this->expectExceptionMessage('The recipe type "test" is not supported.');
36+
37+
RecipeManifest::fromJson(<<<JSON
38+
{
39+
"type": "test"
40+
}
41+
JSON);
42+
}
43+
44+
public function testFromJsonWithMissingName()
45+
{
46+
$this->expectException(\InvalidArgumentException::class);
47+
$this->expectExceptionMessage('Property "name" is required.');
48+
49+
RecipeManifest::fromJson(<<<JSON
50+
{
51+
"type": "component"
52+
}
53+
JSON);
54+
}
55+
56+
public function testFromJsonWithMissingDescription()
57+
{
58+
$this->expectException(\InvalidArgumentException::class);
59+
$this->expectExceptionMessage('Property "description" is required.');
60+
61+
RecipeManifest::fromJson(<<<JSON
62+
{
63+
"type": "component",
64+
"name": "MyComponent"
65+
}
66+
JSON);
67+
}
68+
69+
public function testFromJsonWithMissingLicense()
70+
{
71+
$this->expectException(\InvalidArgumentException::class);
72+
$this->expectExceptionMessage('Property "copy-files" is required.');
73+
74+
RecipeManifest::fromJson(<<<JSON
75+
{
76+
"type": "component",
77+
"name": "MyComponent",
78+
"description": "An incredible component"
79+
}
80+
JSON);
81+
}
82+
83+
public function testFromJsonWithInvalidDependencies()
84+
{
85+
$this->expectException(\InvalidArgumentException::class);
86+
$this->expectExceptionMessage('Each dependency must be an associative array.');
87+
88+
RecipeManifest::fromJson(<<<JSON
89+
{
90+
"type": "component",
91+
"name": "MyComponent",
92+
"description": "An incredible component",
93+
"copy-files": {
94+
"templates/": "templates/"
95+
},
96+
"dependencies": ["foo"]
97+
}
98+
JSON);
99+
}
100+
101+
public function testFromJsonWithInvalidDependenciesType()
102+
{
103+
$this->expectException(\InvalidArgumentException::class);
104+
$this->expectExceptionMessage('The dependency type is missing for dependency #0, add "type" key.');
105+
106+
RecipeManifest::fromJson(<<<JSON
107+
{
108+
"type": "component",
109+
"name": "MyComponent",
110+
"description": "An incredible component",
111+
"copy-files": {
112+
"templates/": "templates/"
113+
},
114+
"dependencies": [
115+
{"key": "value"}
116+
]
117+
}
118+
JSON);
119+
}
120+
121+
public function testFromJsonWithInvalidPhpDependency()
122+
{
123+
$this->expectException(\InvalidArgumentException::class);
124+
$this->expectExceptionMessage('The package name is missing for dependency #0, add "package" key.');
125+
126+
RecipeManifest::fromJson(<<<JSON
127+
{
128+
"type": "component",
129+
"name": "MyComponent",
130+
"description": "An incredible component",
131+
"copy-files": {
132+
"templates/": "templates/"
133+
},
134+
"dependencies": [
135+
{"type": "php"}
136+
]
137+
}
138+
JSON);
139+
}
140+
141+
public function testFromJsonWithInvalidRecipeDependency()
142+
{
143+
$this->expectException(\InvalidArgumentException::class);
144+
$this->expectExceptionMessage('The recipe name is missing for dependency #0, add "name" key.');
145+
146+
RecipeManifest::fromJson(<<<JSON
147+
{
148+
"type": "component",
149+
"name": "MyComponent",
150+
"description": "An incredible component",
151+
"copy-files": {
152+
"templates/": "templates/"
153+
},
154+
"dependencies": [
155+
{"type": "recipe"}
156+
]
157+
}
158+
JSON);
159+
}
160+
161+
public function testFromJsonWithMinimumValidData()
162+
{
163+
$manifest = RecipeManifest::fromJson(<<<JSON
164+
{
165+
"type": "component",
166+
"name": "MyComponent",
167+
"description": "An incredible component",
168+
"copy-files": {
169+
"templates/": "templates/"
170+
}
171+
}
172+
JSON);
173+
174+
$this->assertSame(RecipeType::Component, $manifest->type);
175+
$this->assertSame('MyComponent', $manifest->name);
176+
$this->assertSame('An incredible component', $manifest->description);
177+
$this->assertSame(['templates/' => 'templates/'], $manifest->copyFiles);
178+
$this->assertEquals([], $manifest->dependencies);
179+
}
180+
181+
public function testFromJsonWithValidData()
182+
{
183+
$manifest = RecipeManifest::fromJson(<<<JSON
184+
{
185+
"type": "component",
186+
"name": "MyComponent",
187+
"description": "An incredible component",
188+
"copy-files": {
189+
"templates/": "templates/"
190+
},
191+
"dependencies": [
192+
{
193+
"type": "php",
194+
"package": "symfony/ux-twig-component:^2.29"
195+
},
196+
{
197+
"type": "recipe",
198+
"name": "OtherComponent"
199+
}
200+
]
201+
}
202+
JSON);
203+
204+
$this->assertSame(RecipeType::Component, $manifest->type);
205+
$this->assertSame('MyComponent', $manifest->name);
206+
$this->assertSame('An incredible component', $manifest->description);
207+
$this->assertSame(['templates/' => 'templates/'], $manifest->copyFiles);
208+
$this->assertEquals([
209+
new PhpPackageDependency('symfony/ux-twig-component', new Version('^2.29')),
210+
new RecipeDependency('OtherComponent'),
211+
], $manifest->dependencies);
212+
}
213+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\UX\Toolkit\Tests\Recipe;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\Finder\SplFileInfo;
9+
use Symfony\UX\Toolkit\Kit\Kit;
10+
use Symfony\UX\Toolkit\Kit\KitManifest;
11+
use Symfony\UX\Toolkit\Recipe\RecipeSynchronizer;
12+
13+
final class RecipeSynchronizerTest extends TestCase
14+
{
15+
public function testSynchronize()
16+
{
17+
$kit = new Kit(__DIR__, new KitManifest('foo', 'Description', 'MIT', 'https://example.com'));
18+
$recipeSynchronizer = new RecipeSynchronizer();
19+
20+
$this->assertEmpty($kit->getRecipes());
21+
22+
$recipeSynchronizer->synchronizeRecipe($kit, new SplFileInfo(__DIR__.'/../../kits/shadcn/Alert/manifest.json', 'Alert', 'Alert/manifest.json'));
23+
24+
$recipeAlert = $kit->getRecipe('Alert');
25+
$this->assertNotNull($recipeAlert);
26+
$this->assertEquals('Alert', $recipeAlert->manifest->name);
27+
$this->assertEquals('A notification component that displays important messages with an icon, title, and description.', $recipeAlert->manifest->description);
28+
}
29+
}

0 commit comments

Comments
 (0)