Skip to content

Commit 6516924

Browse files
authored
chore: install command improvements (#628)
1 parent 6a5a5d5 commit 6516924

File tree

4 files changed

+19
-159
lines changed

4 files changed

+19
-159
lines changed

src/Tempest/Core/src/Commands/InstallCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public function __invoke(?string $installer = null): void
2929
{
3030
$installer = $this->resolveInstaller($installer);
3131

32+
if ($installer === null) {
33+
$this->error('Installer not found');
34+
35+
return;
36+
}
37+
3238
if (! $this->confirm("Running the `{$installer->getName()}` installer, continue?")) {
3339
$this->error('Aborted');
3440

@@ -40,7 +46,7 @@ public function __invoke(?string $installer = null): void
4046
$this->success('Done');
4147
}
4248

43-
private function resolveInstaller(?string $search): Installer
49+
private function resolveInstaller(?string $search): ?Installer
4450
{
4551
/** @var Installer[]|\Tempest\Support\ArrayHelper $installers */
4652
$installers = arr($this->installerConfig->installers)

src/Tempest/Generation/tests/ClassManipulatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class ClassManipulatorTest extends TestCase
1919
{
2020
public function test_from_file(): void
2121
{
22-
$class = new ClassManipulator(__FILE__);
22+
$class = new ClassManipulator(__DIR__ . '/Fixtures/ClassFromFile.php');
2323

2424
$this->assertMatchesSnapshot($class->print());
2525
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Generation\Tests\Fixtures;
6+
7+
final readonly class ClassFromFile
8+
{
9+
}
Lines changed: 2 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,7 @@
11
<?php
22

3-
namespace Tempest\Generation\Tests;
3+
namespace Tempest\Generation\Tests\Fixtures;
44

5-
use PHPUnit\Framework\Attributes\Test;
6-
use Tempest\Generation\ClassManipulator;
7-
use Tempest\Generation\Tests\Fixtures\CreateMigrationsTable;
8-
use Tempest\Generation\Tests\Fixtures\Database\MigrationModel;
9-
use Tempest\Generation\Tests\Fixtures\TestAttribute;
10-
use Tempest\Generation\Tests\Fixtures\WelcomeController;
11-
use Tempest\Support\StringHelper;
12-
13-
/**
14-
* @internal
15-
*/
16-
final class ClassManipulatorTest extends TestCase
5+
final readonly class ClassFromFile
176
{
18-
public function test_from_file(): void
19-
{
20-
$class = new ClassManipulator(__FILE__);
21-
22-
$this->assertMatchesSnapshot($class->print());
23-
}
24-
25-
#[Test]
26-
public function updates_namespace(): void
27-
{
28-
$class = new ClassManipulator(CreateMigrationsTable::class);
29-
$class->setNamespace('App');
30-
31-
$this->assertMatchesSnapshot($class->print());
32-
}
33-
34-
#[Test]
35-
public function updates_namespace_multiple_times(): void
36-
{
37-
$class = new ClassManipulator(CreateMigrationsTable::class);
38-
$class->setNamespace('App');
39-
$class->setNamespace('Database');
40-
41-
$this->assertMatchesSnapshot($class->print());
42-
}
43-
44-
#[Test]
45-
public function removes_class_attributes(): void
46-
{
47-
$class = new ClassManipulator(CreateMigrationsTable::class);
48-
$class->removeClassAttribute(TestAttribute::class);
49-
50-
$this->assertMatchesSnapshot($class->print());
51-
}
52-
53-
#[Test]
54-
public function sets_class_final(): void
55-
{
56-
$class = new ClassManipulator(CreateMigrationsTable::class);
57-
$class->setFinal(true);
58-
59-
$this->assertMatchesSnapshot($class->print());
60-
}
61-
62-
#[Test]
63-
public function unsets_class_final(): void
64-
{
65-
$class = new ClassManipulator(CreateMigrationsTable::class);
66-
$class->setFinal(false);
67-
68-
$this->assertMatchesSnapshot($class->print());
69-
}
70-
71-
#[Test]
72-
public function sets_class_readonly(): void
73-
{
74-
$class = new ClassManipulator(CreateMigrationsTable::class);
75-
$class->setReadOnly(true);
76-
77-
$this->assertMatchesSnapshot($class->print());
78-
}
79-
80-
#[Test]
81-
public function unsets_class_readonly(): void
82-
{
83-
$class = new ClassManipulator(CreateMigrationsTable::class);
84-
$class->setReadOnly(false);
85-
86-
$this->assertMatchesSnapshot($class->print());
87-
}
88-
89-
#[Test]
90-
public function sets_strict_types(): void
91-
{
92-
$class = new ClassManipulator(CreateMigrationsTable::class);
93-
$class->setStrictTypes(true);
94-
95-
$this->assertMatchesSnapshot($class->print());
96-
}
97-
98-
#[Test]
99-
public function unsets_strict_types(): void
100-
{
101-
$class = new ClassManipulator(CreateMigrationsTable::class);
102-
$class->setStrictTypes(false);
103-
104-
$this->assertMatchesSnapshot($class->print());
105-
}
106-
107-
#[Test]
108-
public function does_not_simplify_implements_when_specified(): void
109-
{
110-
$class = new ClassManipulator(CreateMigrationsTable::class);
111-
$class->simplifyImplements(false);
112-
113-
$this->assertMatchesSnapshot($class->print());
114-
}
115-
116-
#[Test]
117-
public function set_aliases(): void
118-
{
119-
$class = new ClassManipulator(CreateMigrationsTable::class);
120-
$class->setAlias(MigrationModel::class, 'Model');
121-
122-
$this->assertMatchesSnapshot($class->print());
123-
}
124-
125-
#[Test]
126-
public function simplifies_class_names_by_default(): void
127-
{
128-
$class = new ClassManipulator(CreateMigrationsTable::class);
129-
130-
$this->assertMatchesSnapshot($class->print());
131-
}
132-
133-
#[Test]
134-
public function does_not_simplify_class_names_by_default(): void
135-
{
136-
$class = new ClassManipulator(CreateMigrationsTable::class);
137-
$class->simplifyClassNamesInMethodBodies(false);
138-
139-
$this->assertMatchesSnapshot($class->print());
140-
}
141-
142-
#[Test]
143-
public function transforms_functions(): void
144-
{
145-
$class = new ClassManipulator(WelcomeController::class);
146-
$class->setNamespace('App\\Controllers');
147-
$class->setClassName('WelcomeController');
148-
149-
$this->assertMatchesSnapshot($class->print());
150-
}
151-
152-
#[Test]
153-
public function manipulates_classes(): void
154-
{
155-
$class = new ClassManipulator(WelcomeController::class);
156-
$class->setNamespace('App\\Controllers');
157-
$class->setClassName('WelcomeController');
158-
$class->manipulate(fn (StringHelper $string) => $string->replace('welcome', 'home'));
159-
160-
$this->assertMatchesSnapshot($class->print());
161-
}
1627
}

0 commit comments

Comments
 (0)