Skip to content

Commit c292ff3

Browse files
committed
[FEATURE] Add functional tests for CommandContext
Add functional tests to ensure `CommandContext` works as expected. Tests include validating the return types of `getIo`, `getInput`, and `getOutput` methods with proper mock setups.
1 parent d058910 commit c292ff3

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the package friendsoftypo3/kickstarter.
7+
*
8+
* For the full copyright and license information, please read the
9+
* LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace FriendsOfTYPO3\Kickstarter\Tests\Functional\Context;
13+
14+
use FriendsOfTYPO3\Kickstarter\Context\CommandContext;
15+
use PHPUnit\Framework\Attributes\Test;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
20+
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
21+
22+
class CommandContextTest extends FunctionalTestCase
23+
{
24+
protected CommandContext $subject;
25+
26+
protected InputInterface|MockObject $inputMock;
27+
28+
protected OutputInterface|MockObject $outputMock;
29+
30+
protected array $coreExtensionsToLoad = [
31+
'extensionmanager',
32+
];
33+
34+
protected array $testExtensionsToLoad = [
35+
'friendsoftypo3/kickstarter',
36+
];
37+
38+
protected function setUp(): void
39+
{
40+
$this->inputMock = $this->createMock(InputInterface::class);
41+
$this->outputMock = $this->createMock(OutputInterface::class);
42+
43+
$this->subject = new CommandContext(
44+
$this->inputMock,
45+
$this->outputMock,
46+
);
47+
}
48+
49+
protected function tearDown(): void
50+
{
51+
unset(
52+
$this->inputMock,
53+
$this->outputMock,
54+
$this->subject,
55+
);
56+
}
57+
58+
#[Test]
59+
public function getIoWillReturnObjectOfTypeSymfonyStyle(): void
60+
{
61+
self::assertInstanceOf(
62+
SymfonyStyle::class,
63+
$this->subject->getIo(),
64+
);
65+
}
66+
67+
#[Test]
68+
public function getInputWillReturnObjectOfTypeInputInterface(): void
69+
{
70+
self::assertInstanceOf(
71+
InputInterface::class,
72+
$this->subject->getInput(),
73+
);
74+
75+
self::assertSame(
76+
$this->inputMock,
77+
$this->subject->getInput(),
78+
);
79+
}
80+
81+
#[Test]
82+
public function getOutputWillReturnObjectOfTypeOutputInterface(): void
83+
{
84+
self::assertInstanceOf(
85+
OutputInterface::class,
86+
$this->subject->getOutput(),
87+
);
88+
89+
self::assertSame(
90+
$this->outputMock,
91+
$this->subject->getOutput(),
92+
);
93+
}
94+
}

0 commit comments

Comments
 (0)