Skip to content

Commit 3ec3361

Browse files
authored
[11.x] Test Improvements (#56849)
Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 421211d commit 3ec3361

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"league/flysystem-read-only": "^3.25.1",
112112
"league/flysystem-sftp-v3": "^3.25.1",
113113
"mockery/mockery": "^1.6.10",
114-
"orchestra/testbench-core": "^9.16.0",
114+
"orchestra/testbench-core": "^9.16.1",
115115
"pda/pheanstalk": "^5.0.6",
116116
"php-http/discovery": "^1.15",
117117
"phpstan/phpstan": "^2.0",

src/Illuminate/Testing/PendingCommand.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Helper\Table;
1818
use Symfony\Component\Console\Input\ArrayInput;
1919
use Symfony\Component\Console\Output\BufferedOutput;
20+
use Symfony\Component\Console\Output\ConsoleOutput;
2021
use Symfony\Component\Console\Question\ChoiceQuestion;
2122

2223
class PendingCommand
@@ -359,6 +360,27 @@ public function run()
359360
return $exitCode;
360361
}
361362

363+
/**
364+
* Debug the command.
365+
*
366+
* @return never
367+
*/
368+
public function dd()
369+
{
370+
$consoleOutput = new OutputStyle(new ArrayInput($this->parameters), new ConsoleOutput());
371+
$exitCode = $this->app->make(Kernel::class)->call($this->command, $this->parameters, $consoleOutput);
372+
373+
$streamOutput = $consoleOutput->getOutput()->getStream();
374+
$output = stream_get_contents($streamOutput);
375+
376+
fclose($streamOutput);
377+
378+
dd([
379+
'exitCode' => $exitCode,
380+
'output' => $output,
381+
]);
382+
}
383+
362384
/**
363385
* Determine if expected questions / choices / outputs are fulfilled.
364386
*

tests/Filesystem/FilesystemTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use SplFileInfo;
1616

17+
use function Orchestra\Testbench\terminate;
18+
1719
class FilesystemTest extends TestCase
1820
{
1921
private static $tempDir;
@@ -547,7 +549,7 @@ public function testSharedGet()
547549
$files->put(self::$tempDir.'/file.txt', $content, true);
548550
$read = $files->get(self::$tempDir.'/file.txt', true);
549551

550-
exit(strlen($read) === strlen($content) ? 1 : 0);
552+
terminate($this, strlen($read) === strlen($content) ? 1 : 0);
551553
}
552554
}
553555

tests/Testing/Console/RouteListCommandTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Illuminate\Foundation\Testing\Concerns\InteractsWithDeprecationHandling;
99
use Illuminate\Http\RedirectResponse;
1010
use Illuminate\Routing\Controller;
11-
use Illuminate\Support\Facades\Facade;
1211
use Orchestra\Testbench\TestCase;
1312

1413
class RouteListCommandTest extends TestCase
@@ -123,6 +122,10 @@ public function testRouteCanBeFilteredByAction()
123122
{
124123
$this->withoutDeprecationHandling();
125124

125+
RouteListCommand::resolveTerminalWidthUsing(function () {
126+
return 82;
127+
});
128+
126129
$this->router->get('/', function () {
127130
//
128131
});
@@ -135,7 +138,7 @@ public function testRouteCanBeFilteredByAction()
135138
' GET|HEAD foo/{user} Illuminate\Tests\Testing\Console\FooController@show'
136139
)->expectsOutput('')
137140
->expectsOutput(
138-
' Showing [1] routes'
141+
' Showing [1] routes'
139142
)
140143
->expectsOutput('');
141144
}
@@ -156,15 +159,6 @@ public function testDisplayRoutesExceptVendor()
156159
->expectsOutput(' Showing [3] routes')
157160
->expectsOutput('');
158161
}
159-
160-
protected function tearDown(): void
161-
{
162-
parent::tearDown();
163-
164-
Facade::setFacadeApplication(null);
165-
166-
RouteListCommand::resolveTerminalWidthUsing(null);
167-
}
168162
}
169163

170164
class FooController extends Controller

0 commit comments

Comments
 (0)