Skip to content

Commit d671690

Browse files
committed
Clean up runningInConsole tests and update App facade docs
- Remove queue job test that didn't actually test the PR's functionality - Remove CaptureRunningInConsoleJob fixture (100+ lines of boilerplate) - Rename test method to accurately reflect what it tests - Regenerate App facade docblocks to include new methods
1 parent 829a6e1 commit d671690

File tree

2 files changed

+5
-134
lines changed

2 files changed

+5
-134
lines changed

src/support/src/Facades/App.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
* @method static string getFallbackLocale()
4545
* @method static void setLocale(string $locale)
4646
* @method static string getNamespace()
47+
* @method static bool runningInConsole()
48+
* @method static void markAsRunningInConsole()
4749
* @method static mixed make(string $name, array $parameters = [])
4850
* @method static mixed get(string $id)
4951
* @method static void set(string $name, mixed $entry)

tests/Foundation/FoundationRunningInConsoleTest.php

Lines changed: 3 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
use Hypervel\Console\Contracts\EventMutex;
99
use Hypervel\Console\Scheduling\Event;
1010
use Hypervel\Foundation\Console\Contracts\Kernel as KernelContract;
11-
use Hypervel\Queue\Contracts\Job as JobContract;
1211
use Hypervel\Support\Facades\Artisan;
1312
use Hypervel\Testbench\TestCase;
1413
use Mockery as m;
1514
use Symfony\Component\Console\Input\ArrayInput;
1615
use Symfony\Component\Console\Output\BufferedOutput;
17-
use Throwable;
1816

1917
/**
2018
* @internal
@@ -30,7 +28,6 @@ protected function setUp(): void
3028
CaptureRunningInConsoleCommand::$capturedValue = null;
3129
NestedCallerCommand::$capturedValueBeforeCall = null;
3230
NestedCallerCommand::$capturedValueAfterCall = null;
33-
CaptureRunningInConsoleJob::$capturedValue = null;
3431
}
3532

3633
protected function tearDown(): void
@@ -106,10 +103,10 @@ public function testCodeInsideCliCommandSeesRunningInConsoleTrue(): void
106103
$this->assertTrue(CaptureRunningInConsoleCommand::$capturedValue);
107104
}
108105

109-
public function testCodeInsideArtisanCallFromHttpSeesRunningInConsoleFalse(): void
106+
public function testCodeInsideKernelCallWithoutPriorHandleSeesRunningInConsoleFalse(): void
110107
{
111-
// When Artisan::call() is used from HTTP context (e.g., controller),
112-
// code inside the command should see runningInConsole() = false
108+
// When Kernel::call() is used without a prior Kernel::handle() (e.g., from
109+
// HTTP context), code inside the command should see runningInConsole() = false
113110

114111
$this->registerCaptureCommand();
115112

@@ -177,25 +174,6 @@ public function testScheduledCommandInheritsConsoleContext(): void
177174
);
178175
}
179176

180-
public function testQueueJobSeesRunningInConsoleFalse(): void
181-
{
182-
// Queue jobs run in the queue worker context, which does NOT go through
183-
// Kernel::handle(). Jobs should see runningInConsole() = false.
184-
185-
// Ensure we're NOT in console context (simulating queue worker)
186-
$this->assertFalse($this->app->runningInConsole());
187-
188-
// Create and fire a fake job
189-
$job = new CaptureRunningInConsoleJob();
190-
$job->fire();
191-
192-
// The job should see runningInConsole() = false
193-
$this->assertFalse(
194-
CaptureRunningInConsoleJob::$capturedValue,
195-
'Queue job should see runningInConsole() = false'
196-
);
197-
}
198-
199177
private function registerCaptureCommand(): void
200178
{
201179
$this->app->bind(CaptureRunningInConsoleCommand::class, CaptureRunningInConsoleCommand::class);
@@ -252,112 +230,3 @@ public function handle(): int
252230
return self::SUCCESS;
253231
}
254232
}
255-
256-
/**
257-
* Fake queue job that captures runningInConsole() value during execution.
258-
*/
259-
class CaptureRunningInConsoleJob implements JobContract
260-
{
261-
public static ?bool $capturedValue = null;
262-
263-
public function fire(): void
264-
{
265-
self::$capturedValue = app()->runningInConsole();
266-
}
267-
268-
public function getJobId(): string|int|null
269-
{
270-
return 'test-job-id';
271-
}
272-
273-
public function release(int $delay = 0): void
274-
{
275-
}
276-
277-
public function isReleased(): bool
278-
{
279-
return false;
280-
}
281-
282-
public function delete(): void
283-
{
284-
}
285-
286-
public function isDeleted(): bool
287-
{
288-
return false;
289-
}
290-
291-
public function isDeletedOrReleased(): bool
292-
{
293-
return false;
294-
}
295-
296-
public function attempts(): int
297-
{
298-
return 1;
299-
}
300-
301-
public function hasFailed(): bool
302-
{
303-
return false;
304-
}
305-
306-
public function markAsFailed(): void
307-
{
308-
}
309-
310-
public function fail(?Throwable $e = null): void
311-
{
312-
}
313-
314-
public function maxTries(): ?int
315-
{
316-
return null;
317-
}
318-
319-
public function maxExceptions(): ?int
320-
{
321-
return null;
322-
}
323-
324-
public function timeout(): ?int
325-
{
326-
return null;
327-
}
328-
329-
public function retryUntil(): ?int
330-
{
331-
return null;
332-
}
333-
334-
public function getName(): string
335-
{
336-
return 'CaptureRunningInConsoleJob';
337-
}
338-
339-
public function resolveName(): string
340-
{
341-
return self::class;
342-
}
343-
344-
public function getConnectionName(): string
345-
{
346-
return 'sync';
347-
}
348-
349-
public function getQueue(): string
350-
{
351-
return 'default';
352-
}
353-
354-
public function getRawBody(): string
355-
{
356-
return '{}';
357-
}
358-
359-
public function uuid(): ?string
360-
{
361-
return 'test-uuid';
362-
}
363-
}

0 commit comments

Comments
 (0)