mirror of
https://github.com/itflow-org/itflow
synced 2026-03-01 03:14:52 +00:00
Reintroduce Webklex IMAP for ticket processing as PHP-IMAP is no longer being developed. This is optional for now and considered beta can be found in cron/ticket_email_parser.php
This commit is contained in:
168
plugins/vendor/illuminate/support/Testing/Fakes/BatchFake.php
vendored
Normal file
168
plugins/vendor/illuminate/support/Testing/Fakes/BatchFake.php
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Bus\Batch;
|
||||
use Illuminate\Bus\UpdatedBatchJobCounts;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class BatchFake extends Batch
|
||||
{
|
||||
/**
|
||||
* The jobs that have been added to the batch.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $added = [];
|
||||
|
||||
/**
|
||||
* Indicates if the batch has been deleted.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleted = false;
|
||||
|
||||
/**
|
||||
* Create a new batch instance.
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $name
|
||||
* @param int $totalJobs
|
||||
* @param int $pendingJobs
|
||||
* @param int $failedJobs
|
||||
* @param array $failedJobIds
|
||||
* @param array $options
|
||||
* @param \Carbon\CarbonImmutable $createdAt
|
||||
* @param \Carbon\CarbonImmutable|null $cancelledAt
|
||||
* @param \Carbon\CarbonImmutable|null $finishedAt
|
||||
*/
|
||||
public function __construct(
|
||||
string $id,
|
||||
string $name,
|
||||
int $totalJobs,
|
||||
int $pendingJobs,
|
||||
int $failedJobs,
|
||||
array $failedJobIds,
|
||||
array $options,
|
||||
CarbonImmutable $createdAt,
|
||||
?CarbonImmutable $cancelledAt = null,
|
||||
?CarbonImmutable $finishedAt = null,
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->totalJobs = $totalJobs;
|
||||
$this->pendingJobs = $pendingJobs;
|
||||
$this->failedJobs = $failedJobs;
|
||||
$this->failedJobIds = $failedJobIds;
|
||||
$this->options = $options;
|
||||
$this->createdAt = $createdAt;
|
||||
$this->cancelledAt = $cancelledAt;
|
||||
$this->finishedAt = $finishedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a fresh instance of the batch represented by this ID.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function fresh()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add additional jobs to the batch.
|
||||
*
|
||||
* @param \Illuminate\Support\Enumerable|object|array $jobs
|
||||
* @return self
|
||||
*/
|
||||
public function add($jobs)
|
||||
{
|
||||
$jobs = Collection::wrap($jobs);
|
||||
|
||||
foreach ($jobs as $job) {
|
||||
$this->added[] = $job;
|
||||
}
|
||||
|
||||
$this->totalJobs += $jobs->count();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that a job within the batch finished successfully, executing any callbacks if necessary.
|
||||
*
|
||||
* @param string $jobId
|
||||
* @return void
|
||||
*/
|
||||
public function recordSuccessfulJob(string $jobId)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the pending jobs for the batch.
|
||||
*
|
||||
* @param string $jobId
|
||||
* @return void
|
||||
*/
|
||||
public function decrementPendingJobs(string $jobId)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that a job within the batch failed to finish successfully, executing any callbacks if necessary.
|
||||
*
|
||||
* @param string $jobId
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
public function recordFailedJob(string $jobId, $e)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the failed jobs for the batch.
|
||||
*
|
||||
* @param string $jobId
|
||||
* @return \Illuminate\Bus\UpdatedBatchJobCounts
|
||||
*/
|
||||
public function incrementFailedJobs(string $jobId)
|
||||
{
|
||||
return new UpdatedBatchJobCounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the batch.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
$this->cancelledAt = Carbon::now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the batch from storage.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->deleted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the batch has been deleted.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleted()
|
||||
{
|
||||
return $this->deleted;
|
||||
}
|
||||
}
|
||||
163
plugins/vendor/illuminate/support/Testing/Fakes/BatchRepositoryFake.php
vendored
Normal file
163
plugins/vendor/illuminate/support/Testing/Fakes/BatchRepositoryFake.php
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Closure;
|
||||
use Illuminate\Bus\BatchRepository;
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use Illuminate\Bus\UpdatedBatchJobCounts;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BatchRepositoryFake implements BatchRepository
|
||||
{
|
||||
/**
|
||||
* The batches stored in the repository.
|
||||
*
|
||||
* @var \Illuminate\Bus\Batch[]
|
||||
*/
|
||||
protected $batches = [];
|
||||
|
||||
/**
|
||||
* Retrieve a list of batches.
|
||||
*
|
||||
* @param int $limit
|
||||
* @param mixed $before
|
||||
* @return \Illuminate\Bus\Batch[]
|
||||
*/
|
||||
public function get($limit, $before)
|
||||
{
|
||||
return $this->batches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve information about an existing batch.
|
||||
*
|
||||
* @param string $batchId
|
||||
* @return \Illuminate\Bus\Batch|null
|
||||
*/
|
||||
public function find(string $batchId)
|
||||
{
|
||||
return $this->batches[$batchId] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a new pending batch.
|
||||
*
|
||||
* @param \Illuminate\Bus\PendingBatch $batch
|
||||
* @return \Illuminate\Bus\Batch
|
||||
*/
|
||||
public function store(PendingBatch $batch)
|
||||
{
|
||||
$id = (string) Str::orderedUuid();
|
||||
|
||||
$this->batches[$id] = new BatchFake(
|
||||
$id,
|
||||
$batch->name,
|
||||
count($batch->jobs),
|
||||
count($batch->jobs),
|
||||
0,
|
||||
[],
|
||||
$batch->options,
|
||||
CarbonImmutable::now(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return $this->batches[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the total number of jobs within the batch.
|
||||
*
|
||||
* @param string $batchId
|
||||
* @param int $amount
|
||||
* @return void
|
||||
*/
|
||||
public function incrementTotalJobs(string $batchId, int $amount)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the total number of pending jobs for the batch.
|
||||
*
|
||||
* @param string $batchId
|
||||
* @param string $jobId
|
||||
* @return \Illuminate\Bus\UpdatedBatchJobCounts
|
||||
*/
|
||||
public function decrementPendingJobs(string $batchId, string $jobId)
|
||||
{
|
||||
return new UpdatedBatchJobCounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the total number of failed jobs for the batch.
|
||||
*
|
||||
* @param string $batchId
|
||||
* @param string $jobId
|
||||
* @return \Illuminate\Bus\UpdatedBatchJobCounts
|
||||
*/
|
||||
public function incrementFailedJobs(string $batchId, string $jobId)
|
||||
{
|
||||
return new UpdatedBatchJobCounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the batch that has the given ID as finished.
|
||||
*
|
||||
* @param string $batchId
|
||||
* @return void
|
||||
*/
|
||||
public function markAsFinished(string $batchId)
|
||||
{
|
||||
if (isset($this->batches[$batchId])) {
|
||||
$this->batches[$batchId]->finishedAt = now();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the batch that has the given ID.
|
||||
*
|
||||
* @param string $batchId
|
||||
* @return void
|
||||
*/
|
||||
public function cancel(string $batchId)
|
||||
{
|
||||
if (isset($this->batches[$batchId])) {
|
||||
$this->batches[$batchId]->cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the batch that has the given ID.
|
||||
*
|
||||
* @param string $batchId
|
||||
* @return void
|
||||
*/
|
||||
public function delete(string $batchId)
|
||||
{
|
||||
unset($this->batches[$batchId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the given Closure within a storage specific transaction.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function transaction(Closure $callback)
|
||||
{
|
||||
return $callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback the last database transaction for the connection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rollBack()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
925
plugins/vendor/illuminate/support/Testing/Fakes/BusFake.php
vendored
Normal file
925
plugins/vendor/illuminate/support/Testing/Fakes/BusFake.php
vendored
Normal file
@@ -0,0 +1,925 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Bus\BatchRepository;
|
||||
use Illuminate\Bus\ChainedBatch;
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use Illuminate\Contracts\Bus\QueueingDispatcher;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Traits\ReflectsClosures;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
use RuntimeException;
|
||||
|
||||
class BusFake implements Fake, QueueingDispatcher
|
||||
{
|
||||
use ReflectsClosures;
|
||||
|
||||
/**
|
||||
* The original Bus dispatcher implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Bus\QueueingDispatcher
|
||||
*/
|
||||
public $dispatcher;
|
||||
|
||||
/**
|
||||
* The job types that should be intercepted instead of dispatched.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $jobsToFake = [];
|
||||
|
||||
/**
|
||||
* The job types that should be dispatched instead of faked.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $jobsToDispatch = [];
|
||||
|
||||
/**
|
||||
* The fake repository to track batched jobs.
|
||||
*
|
||||
* @var \Illuminate\Bus\BatchRepository
|
||||
*/
|
||||
protected $batchRepository;
|
||||
|
||||
/**
|
||||
* The commands that have been dispatched.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [];
|
||||
|
||||
/**
|
||||
* The commands that have been dispatched synchronously.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commandsSync = [];
|
||||
|
||||
/**
|
||||
* The commands that have been dispatched after the response has been sent.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commandsAfterResponse = [];
|
||||
|
||||
/**
|
||||
* The batches that have been dispatched.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $batches = [];
|
||||
|
||||
/**
|
||||
* Indicates if commands should be serialized and restored when pushed to the Bus.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $serializeAndRestore = false;
|
||||
|
||||
/**
|
||||
* Create a new bus fake instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Bus\QueueingDispatcher $dispatcher
|
||||
* @param array|string $jobsToFake
|
||||
* @param \Illuminate\Bus\BatchRepository|null $batchRepository
|
||||
*/
|
||||
public function __construct(QueueingDispatcher $dispatcher, $jobsToFake = [], ?BatchRepository $batchRepository = null)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->jobsToFake = Arr::wrap($jobsToFake);
|
||||
$this->batchRepository = $batchRepository ?: new BatchRepositoryFake;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the jobs that should be dispatched instead of faked.
|
||||
*
|
||||
* @param array|string $jobsToDispatch
|
||||
* @return $this
|
||||
*/
|
||||
public function except($jobsToDispatch)
|
||||
{
|
||||
$this->jobsToDispatch = array_merge($this->jobsToDispatch, Arr::wrap($jobsToDispatch));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was dispatched based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param callable|int|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatched($command, $callback = null)
|
||||
{
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
if (is_numeric($callback)) {
|
||||
return $this->assertDispatchedTimes($command, $callback);
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->dispatched($command, $callback)->count() > 0 ||
|
||||
$this->dispatchedAfterResponse($command, $callback)->count() > 0 ||
|
||||
$this->dispatchedSync($command, $callback)->count() > 0,
|
||||
"The expected [{$command}] job was not dispatched."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed exactly once.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedOnce($command)
|
||||
{
|
||||
$this->assertDispatchedTimes($command, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed a number of times.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedTimes($command, $times = 1)
|
||||
{
|
||||
$callback = null;
|
||||
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
$count = $this->dispatched($command, $callback)->count() +
|
||||
$this->dispatchedAfterResponse($command, $callback)->count() +
|
||||
$this->dispatchedSync($command, $callback)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$times, $count,
|
||||
sprintf(
|
||||
"The expected [{$command}] job was pushed {$count} %s instead of {$times} %s.",
|
||||
Str::plural('time', $count),
|
||||
Str::plural('time', $times)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a job was dispatched based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotDispatched($command, $callback = null)
|
||||
{
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->dispatched($command, $callback)->count() === 0 &&
|
||||
$this->dispatchedAfterResponse($command, $callback)->count() === 0 &&
|
||||
$this->dispatchedSync($command, $callback)->count() === 0,
|
||||
"The unexpected [{$command}] job was dispatched."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no jobs were dispatched.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingDispatched()
|
||||
{
|
||||
$commandNames = implode("\n- ", array_keys($this->commands));
|
||||
|
||||
PHPUnit::assertEmpty($this->commands, "The following jobs were dispatched unexpectedly:\n\n- $commandNames\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was explicitly dispatched synchronously based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param callable|int|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedSync($command, $callback = null)
|
||||
{
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
if (is_numeric($callback)) {
|
||||
return $this->assertDispatchedSyncTimes($command, $callback);
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->dispatchedSync($command, $callback)->count() > 0,
|
||||
"The expected [{$command}] job was not dispatched synchronously."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed synchronously a number of times.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedSyncTimes($command, $times = 1)
|
||||
{
|
||||
$callback = null;
|
||||
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
$count = $this->dispatchedSync($command, $callback)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$times, $count,
|
||||
sprintf(
|
||||
"The expected [{$command}] job was synchronously pushed {$count} %s instead of {$times} %s.",
|
||||
Str::plural('time', $count),
|
||||
Str::plural('time', $times)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a job was dispatched based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotDispatchedSync($command, $callback = null)
|
||||
{
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->dispatchedSync($command, $callback),
|
||||
"The unexpected [{$command}] job was dispatched synchronously."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was dispatched after the response was sent based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param callable|int|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedAfterResponse($command, $callback = null)
|
||||
{
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
if (is_numeric($callback)) {
|
||||
return $this->assertDispatchedAfterResponseTimes($command, $callback);
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
|
||||
"The expected [{$command}] job was not dispatched after sending the response."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed after the response was sent a number of times.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedAfterResponseTimes($command, $times = 1)
|
||||
{
|
||||
$callback = null;
|
||||
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
$count = $this->dispatchedAfterResponse($command, $callback)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$times, $count,
|
||||
sprintf(
|
||||
"The expected [{$command}] job was pushed {$count} %s instead of {$times} %s.",
|
||||
Str::plural('time', $count),
|
||||
Str::plural('time', $times)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a job was dispatched based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotDispatchedAfterResponse($command, $callback = null)
|
||||
{
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->dispatchedAfterResponse($command, $callback),
|
||||
"The unexpected [{$command}] job was dispatched after sending the response."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a chain of jobs was dispatched.
|
||||
*
|
||||
* @param array $expectedChain
|
||||
* @return void
|
||||
*/
|
||||
public function assertChained(array $expectedChain)
|
||||
{
|
||||
$command = $expectedChain[0];
|
||||
|
||||
$expectedChain = array_slice($expectedChain, 1);
|
||||
|
||||
$callback = null;
|
||||
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
} elseif ($command instanceof ChainedBatchTruthTest) {
|
||||
$instance = $command;
|
||||
|
||||
$command = ChainedBatch::class;
|
||||
|
||||
$callback = fn ($job) => $instance($job->toPendingBatch());
|
||||
} elseif (! is_string($command)) {
|
||||
$instance = $command;
|
||||
|
||||
$command = get_class($instance);
|
||||
|
||||
$callback = function ($job) use ($instance) {
|
||||
return serialize($this->resetChainPropertiesToDefaults($job)) === serialize($instance);
|
||||
};
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->dispatched($command, $callback)->isNotEmpty(),
|
||||
"The expected [{$command}] job was not dispatched."
|
||||
);
|
||||
|
||||
$this->assertDispatchedWithChainOfObjects($command, $expectedChain, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert no chained jobs was dispatched.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingChained()
|
||||
{
|
||||
$this->assertNothingDispatched();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the chain properties to their default values on the job.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @return mixed
|
||||
*/
|
||||
protected function resetChainPropertiesToDefaults($job)
|
||||
{
|
||||
return tap(clone $job, function ($job) {
|
||||
$job->chainConnection = null;
|
||||
$job->chainQueue = null;
|
||||
$job->chainCatchCallbacks = null;
|
||||
$job->chained = [];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was dispatched with an empty chain based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $command
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedWithoutChain($command, $callback = null)
|
||||
{
|
||||
if ($command instanceof Closure) {
|
||||
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->dispatched($command, $callback)->isNotEmpty(),
|
||||
"The expected [{$command}] job was not dispatched."
|
||||
);
|
||||
|
||||
$this->assertDispatchedWithChainOfObjects($command, [], $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was dispatched with chained jobs based on a truth-test callback.
|
||||
*
|
||||
* @param string $command
|
||||
* @param array $expectedChain
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
protected function assertDispatchedWithChainOfObjects($command, $expectedChain, $callback)
|
||||
{
|
||||
$chain = $expectedChain;
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->dispatched($command, $callback)->filter(function ($job) use ($chain) {
|
||||
if (count($chain) !== count($job->chained)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($job->chained as $index => $serializedChainedJob) {
|
||||
if ($chain[$index] instanceof ChainedBatchTruthTest) {
|
||||
$chainedBatch = unserialize($serializedChainedJob);
|
||||
|
||||
if (! $chainedBatch instanceof ChainedBatch ||
|
||||
! $chain[$index]($chainedBatch->toPendingBatch())) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($chain[$index] instanceof Closure) {
|
||||
[$expectedType, $callback] = [$this->firstClosureParameterType($chain[$index]), $chain[$index]];
|
||||
|
||||
$chainedJob = unserialize($serializedChainedJob);
|
||||
|
||||
if (! $chainedJob instanceof $expectedType) {
|
||||
throw new RuntimeException('The chained job was expected to be of type '.$expectedType.', '.$chainedJob::class.' chained.');
|
||||
}
|
||||
|
||||
if (! $callback($chainedJob)) {
|
||||
return false;
|
||||
}
|
||||
} elseif (is_string($chain[$index])) {
|
||||
if ($chain[$index] != get_class(unserialize($serializedChainedJob))) {
|
||||
return false;
|
||||
}
|
||||
} elseif (serialize($chain[$index]) != $serializedChainedJob) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
})->isNotEmpty(),
|
||||
'The expected chain was not dispatched.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new assertion about a chained batch.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return \Illuminate\Support\Testing\Fakes\ChainedBatchTruthTest
|
||||
*/
|
||||
public function chainedBatch(Closure $callback)
|
||||
{
|
||||
return new ChainedBatchTruthTest($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a batch was dispatched based on a truth-test callback.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertBatched(callable $callback)
|
||||
{
|
||||
PHPUnit::assertTrue(
|
||||
$this->batched($callback)->count() > 0,
|
||||
'The expected batch was not dispatched.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the number of batches that have been dispatched.
|
||||
*
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
public function assertBatchCount($count)
|
||||
{
|
||||
PHPUnit::assertCount(
|
||||
$count, $this->batches,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no batched jobs were dispatched.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingBatched()
|
||||
{
|
||||
$jobNames = (new Collection($this->batches))
|
||||
->map(fn ($batch) => $batch->jobs->map(fn ($job) => get_class($job)))
|
||||
->flatten()
|
||||
->join("\n- ");
|
||||
|
||||
PHPUnit::assertEmpty($this->batches, "The following batched jobs were dispatched unexpectedly:\n\n- $jobNames\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no jobs were dispatched, chained, or batched.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingPlaced()
|
||||
{
|
||||
$this->assertNothingDispatched();
|
||||
$this->assertNothingBatched();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the jobs matching a truth-test callback.
|
||||
*
|
||||
* @param string $command
|
||||
* @param callable|null $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function dispatched($command, $callback = null)
|
||||
{
|
||||
if (! $this->hasDispatched($command)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$callback = $callback ?: fn () => true;
|
||||
|
||||
return (new Collection($this->commands[$command]))->filter(fn ($command) => $callback($command));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the jobs dispatched synchronously matching a truth-test callback.
|
||||
*
|
||||
* @param string $command
|
||||
* @param callable|null $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function dispatchedSync(string $command, $callback = null)
|
||||
{
|
||||
if (! $this->hasDispatchedSync($command)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$callback = $callback ?: fn () => true;
|
||||
|
||||
return (new Collection($this->commandsSync[$command]))->filter(fn ($command) => $callback($command));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the jobs dispatched after the response was sent matching a truth-test callback.
|
||||
*
|
||||
* @param string $command
|
||||
* @param callable|null $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function dispatchedAfterResponse(string $command, $callback = null)
|
||||
{
|
||||
if (! $this->hasDispatchedAfterResponse($command)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$callback = $callback ?: fn () => true;
|
||||
|
||||
return (new Collection($this->commandsAfterResponse[$command]))->filter(fn ($command) => $callback($command));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the pending batches matching a truth-test callback.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function batched(callable $callback)
|
||||
{
|
||||
if (empty($this->batches)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
return (new Collection($this->batches))->filter(fn ($batch) => $callback($batch));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are any stored commands for a given class.
|
||||
*
|
||||
* @param string $command
|
||||
* @return bool
|
||||
*/
|
||||
public function hasDispatched($command)
|
||||
{
|
||||
return isset($this->commands[$command]) && ! empty($this->commands[$command]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are any stored commands for a given class.
|
||||
*
|
||||
* @param string $command
|
||||
* @return bool
|
||||
*/
|
||||
public function hasDispatchedSync($command)
|
||||
{
|
||||
return isset($this->commandsSync[$command]) && ! empty($this->commandsSync[$command]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are any stored commands for a given class.
|
||||
*
|
||||
* @param string $command
|
||||
* @return bool
|
||||
*/
|
||||
public function hasDispatchedAfterResponse($command)
|
||||
{
|
||||
return isset($this->commandsAfterResponse[$command]) && ! empty($this->commandsAfterResponse[$command]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a command to its appropriate handler.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatch($command)
|
||||
{
|
||||
if ($this->shouldFakeJob($command)) {
|
||||
$this->commands[get_class($command)][] = $this->getCommandRepresentation($command);
|
||||
} else {
|
||||
return $this->dispatcher->dispatch($command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a command to its appropriate handler in the current process.
|
||||
*
|
||||
* Queueable jobs will be dispatched to the "sync" queue.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $handler
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatchSync($command, $handler = null)
|
||||
{
|
||||
if ($this->shouldFakeJob($command)) {
|
||||
$this->commandsSync[get_class($command)][] = $this->getCommandRepresentation($command);
|
||||
} else {
|
||||
return $this->dispatcher->dispatchSync($command, $handler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a command to its appropriate handler in the current process.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $handler
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatchNow($command, $handler = null)
|
||||
{
|
||||
if ($this->shouldFakeJob($command)) {
|
||||
$this->commands[get_class($command)][] = $this->getCommandRepresentation($command);
|
||||
} else {
|
||||
return $this->dispatcher->dispatchNow($command, $handler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a command to its appropriate handler behind a queue.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatchToQueue($command)
|
||||
{
|
||||
if ($this->shouldFakeJob($command)) {
|
||||
$this->commands[get_class($command)][] = $this->getCommandRepresentation($command);
|
||||
} else {
|
||||
return $this->dispatcher->dispatchToQueue($command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a command to its appropriate handler.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
public function dispatchAfterResponse($command)
|
||||
{
|
||||
if ($this->shouldFakeJob($command)) {
|
||||
$this->commandsAfterResponse[get_class($command)][] = $this->getCommandRepresentation($command);
|
||||
} else {
|
||||
return $this->dispatcher->dispatch($command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new chain of queueable jobs.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|array|null $jobs
|
||||
* @return \Illuminate\Foundation\Bus\PendingChain
|
||||
*/
|
||||
public function chain($jobs = null)
|
||||
{
|
||||
$jobs = Collection::wrap($jobs);
|
||||
$jobs = ChainedBatch::prepareNestedBatches($jobs);
|
||||
|
||||
return new PendingChainFake($this, $jobs->shift(), $jobs->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to find the batch with the given ID.
|
||||
*
|
||||
* @param string $batchId
|
||||
* @return \Illuminate\Bus\Batch|null
|
||||
*/
|
||||
public function findBatch(string $batchId)
|
||||
{
|
||||
return $this->batchRepository->find($batchId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new batch of queueable jobs.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|array $jobs
|
||||
* @return \Illuminate\Bus\PendingBatch
|
||||
*/
|
||||
public function batch($jobs)
|
||||
{
|
||||
return new PendingBatchFake($this, Collection::wrap($jobs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch an empty job batch for testing.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Bus\Batch
|
||||
*/
|
||||
public function dispatchFakeBatch($name = '')
|
||||
{
|
||||
return $this->batch([])->name($name)->dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Record the fake pending batch dispatch.
|
||||
*
|
||||
* @param \Illuminate\Bus\PendingBatch $pendingBatch
|
||||
* @return \Illuminate\Bus\Batch
|
||||
*/
|
||||
public function recordPendingBatch(PendingBatch $pendingBatch)
|
||||
{
|
||||
$this->batches[] = $pendingBatch;
|
||||
|
||||
return $this->batchRepository->store($pendingBatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a command should be faked or actually dispatched.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldFakeJob($command)
|
||||
{
|
||||
if ($this->shouldDispatchCommand($command)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($this->jobsToFake)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (new Collection($this->jobsToFake))
|
||||
->filter(function ($job) use ($command) {
|
||||
return $job instanceof Closure
|
||||
? $job($command)
|
||||
: $job === get_class($command);
|
||||
})->isNotEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a command should be dispatched or not.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldDispatchCommand($command)
|
||||
{
|
||||
return (new Collection($this->jobsToDispatch))
|
||||
->filter(function ($job) use ($command) {
|
||||
return $job instanceof Closure
|
||||
? $job($command)
|
||||
: $job === get_class($command);
|
||||
})->isNotEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if commands should be serialized and restored when being batched.
|
||||
*
|
||||
* @param bool $serializeAndRestore
|
||||
* @return $this
|
||||
*/
|
||||
public function serializeAndRestore(bool $serializeAndRestore = true)
|
||||
{
|
||||
$this->serializeAndRestore = $serializeAndRestore;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize and unserialize the command to simulate the queueing process.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
protected function serializeAndRestoreCommand($command)
|
||||
{
|
||||
return unserialize(serialize($command));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command representation that should be stored.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getCommandRepresentation($command)
|
||||
{
|
||||
return $this->serializeAndRestore ? $this->serializeAndRestoreCommand($command) : $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pipes commands should be piped through before dispatching.
|
||||
*
|
||||
* @param array $pipes
|
||||
* @return $this
|
||||
*/
|
||||
public function pipeThrough(array $pipes)
|
||||
{
|
||||
$this->dispatcher->pipeThrough($pipes);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given command has a handler.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCommandHandler($command)
|
||||
{
|
||||
return $this->dispatcher->hasCommandHandler($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the handler for a command.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCommandHandler($command)
|
||||
{
|
||||
return $this->dispatcher->getCommandHandler($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a command to a handler.
|
||||
*
|
||||
* @param array $map
|
||||
* @return $this
|
||||
*/
|
||||
public function map(array $map)
|
||||
{
|
||||
$this->dispatcher->map($map);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the batches that have been dispatched.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dispatchedBatches()
|
||||
{
|
||||
return $this->batches;
|
||||
}
|
||||
}
|
||||
36
plugins/vendor/illuminate/support/Testing/Fakes/ChainedBatchTruthTest.php
vendored
Normal file
36
plugins/vendor/illuminate/support/Testing/Fakes/ChainedBatchTruthTest.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Closure;
|
||||
|
||||
class ChainedBatchTruthTest
|
||||
{
|
||||
/**
|
||||
* The underlying truth test.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* Create a new truth test instance.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
*/
|
||||
public function __construct(Closure $callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the truth test with the given pending batch.
|
||||
*
|
||||
* @param \Illuminate\Bus\PendingBatch $pendingBatch
|
||||
* @return bool
|
||||
*/
|
||||
public function __invoke($pendingBatch)
|
||||
{
|
||||
return call_user_func($this->callback, $pendingBatch);
|
||||
}
|
||||
}
|
||||
453
plugins/vendor/illuminate/support/Testing/Fakes/EventFake.php
vendored
Normal file
453
plugins/vendor/illuminate/support/Testing/Fakes/EventFake.php
vendored
Normal file
@@ -0,0 +1,453 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Events\ShouldDispatchAfterCommit;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Traits\ForwardsCalls;
|
||||
use Illuminate\Support\Traits\ReflectsClosures;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
use ReflectionFunction;
|
||||
|
||||
class EventFake implements Dispatcher, Fake
|
||||
{
|
||||
use ForwardsCalls, ReflectsClosures;
|
||||
|
||||
/**
|
||||
* The original event dispatcher.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Events\Dispatcher
|
||||
*/
|
||||
public $dispatcher;
|
||||
|
||||
/**
|
||||
* The event types that should be intercepted instead of dispatched.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $eventsToFake = [];
|
||||
|
||||
/**
|
||||
* The event types that should be dispatched instead of intercepted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $eventsToDispatch = [];
|
||||
|
||||
/**
|
||||
* All of the events that have been intercepted keyed by type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $events = [];
|
||||
|
||||
/**
|
||||
* Create a new event fake instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
|
||||
* @param array|string $eventsToFake
|
||||
*/
|
||||
public function __construct(Dispatcher $dispatcher, $eventsToFake = [])
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
|
||||
$this->eventsToFake = Arr::wrap($eventsToFake);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the events that should be dispatched instead of faked.
|
||||
*
|
||||
* @param array|string $eventsToDispatch
|
||||
* @return $this
|
||||
*/
|
||||
public function except($eventsToDispatch)
|
||||
{
|
||||
$this->eventsToDispatch = array_merge(
|
||||
$this->eventsToDispatch,
|
||||
Arr::wrap($eventsToDispatch)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if an event has a listener attached to it.
|
||||
*
|
||||
* @param string $expectedEvent
|
||||
* @param string|array $expectedListener
|
||||
* @return void
|
||||
*/
|
||||
public function assertListening($expectedEvent, $expectedListener)
|
||||
{
|
||||
foreach ($this->dispatcher->getListeners($expectedEvent) as $listenerClosure) {
|
||||
$actualListener = (new ReflectionFunction($listenerClosure))
|
||||
->getStaticVariables()['listener'];
|
||||
|
||||
$normalizedListener = $expectedListener;
|
||||
|
||||
if (is_string($actualListener) && Str::contains($actualListener, '@')) {
|
||||
$actualListener = Str::parseCallback($actualListener);
|
||||
|
||||
if (is_string($expectedListener)) {
|
||||
if (Str::contains($expectedListener, '@')) {
|
||||
$normalizedListener = Str::parseCallback($expectedListener);
|
||||
} else {
|
||||
$normalizedListener = [
|
||||
$expectedListener,
|
||||
method_exists($expectedListener, 'handle') ? 'handle' : '__invoke',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($actualListener === $normalizedListener ||
|
||||
($actualListener instanceof Closure &&
|
||||
$normalizedListener === Closure::class)) {
|
||||
PHPUnit::assertTrue(true);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
false,
|
||||
sprintf(
|
||||
'Event [%s] does not have the [%s] listener attached to it',
|
||||
$expectedEvent,
|
||||
print_r($expectedListener, true)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if an event was dispatched based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $event
|
||||
* @param callable|int|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatched($event, $callback = null)
|
||||
{
|
||||
if ($event instanceof Closure) {
|
||||
[$event, $callback] = [$this->firstClosureParameterType($event), $event];
|
||||
}
|
||||
|
||||
if (is_int($callback)) {
|
||||
return $this->assertDispatchedTimes($event, $callback);
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->dispatched($event, $callback)->count() > 0,
|
||||
"The expected [{$event}] event was not dispatched."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if an event was dispatched exactly once.
|
||||
*
|
||||
* @param string $event
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedOnce($event)
|
||||
{
|
||||
$this->assertDispatchedTimes($event, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if an event was dispatched a number of times.
|
||||
*
|
||||
* @param string $event
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
public function assertDispatchedTimes($event, $times = 1)
|
||||
{
|
||||
$count = $this->dispatched($event)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$times, $count,
|
||||
sprintf(
|
||||
"The expected [{$event}] event was dispatched {$count} %s instead of {$times} %s.",
|
||||
Str::plural('time', $count),
|
||||
Str::plural('time', $times)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an event was dispatched based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $event
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotDispatched($event, $callback = null)
|
||||
{
|
||||
if ($event instanceof Closure) {
|
||||
[$event, $callback] = [$this->firstClosureParameterType($event), $event];
|
||||
}
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->dispatched($event, $callback),
|
||||
"The unexpected [{$event}] event was dispatched."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no events were dispatched.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingDispatched()
|
||||
{
|
||||
$count = count(Arr::flatten($this->events));
|
||||
|
||||
$eventNames = (new Collection($this->events))
|
||||
->map(fn ($events, $eventName) => sprintf(
|
||||
'%s dispatched %s %s',
|
||||
$eventName,
|
||||
count($events),
|
||||
Str::plural('time', count($events)),
|
||||
))
|
||||
->join("\n- ");
|
||||
|
||||
PHPUnit::assertSame(
|
||||
0, $count,
|
||||
"{$count} unexpected events were dispatched:\n\n- $eventNames\n"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the events matching a truth-test callback.
|
||||
*
|
||||
* @param string $event
|
||||
* @param callable|null $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function dispatched($event, $callback = null)
|
||||
{
|
||||
if (! $this->hasDispatched($event)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$callback = $callback ?: fn () => true;
|
||||
|
||||
return (new Collection($this->events[$event]))->filter(
|
||||
fn ($arguments) => $callback(...$arguments)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given event has been dispatched.
|
||||
*
|
||||
* @param string $event
|
||||
* @return bool
|
||||
*/
|
||||
public function hasDispatched($event)
|
||||
{
|
||||
return isset($this->events[$event]) && ! empty($this->events[$event]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event listener with the dispatcher.
|
||||
*
|
||||
* @param \Closure|string|array $events
|
||||
* @param mixed $listener
|
||||
* @return void
|
||||
*/
|
||||
public function listen($events, $listener = null)
|
||||
{
|
||||
$this->dispatcher->listen($events, $listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given event has listeners.
|
||||
*
|
||||
* @param string $eventName
|
||||
* @return bool
|
||||
*/
|
||||
public function hasListeners($eventName)
|
||||
{
|
||||
return $this->dispatcher->hasListeners($eventName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event and payload to be dispatched later.
|
||||
*
|
||||
* @param string $event
|
||||
* @param array $payload
|
||||
* @return void
|
||||
*/
|
||||
public function push($event, $payload = [])
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event subscriber with the dispatcher.
|
||||
*
|
||||
* @param object|string $subscriber
|
||||
* @return void
|
||||
*/
|
||||
public function subscribe($subscriber)
|
||||
{
|
||||
$this->dispatcher->subscribe($subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush a set of pushed events.
|
||||
*
|
||||
* @param string $event
|
||||
* @return void
|
||||
*/
|
||||
public function flush($event)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire an event and call the listeners.
|
||||
*
|
||||
* @param string|object $event
|
||||
* @param mixed $payload
|
||||
* @param bool $halt
|
||||
* @return array|null
|
||||
*/
|
||||
public function dispatch($event, $payload = [], $halt = false)
|
||||
{
|
||||
$name = is_object($event) ? get_class($event) : (string) $event;
|
||||
|
||||
if ($this->shouldFakeEvent($name, $payload)) {
|
||||
$this->fakeEvent($event, $name, func_get_args());
|
||||
} else {
|
||||
return $this->dispatcher->dispatch($event, $payload, $halt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an event should be faked or actually dispatched.
|
||||
*
|
||||
* @param string $eventName
|
||||
* @param mixed $payload
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldFakeEvent($eventName, $payload)
|
||||
{
|
||||
if ($this->shouldDispatchEvent($eventName, $payload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($this->eventsToFake)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (new Collection($this->eventsToFake))
|
||||
->filter(function ($event) use ($eventName, $payload) {
|
||||
return $event instanceof Closure
|
||||
? $event($eventName, $payload)
|
||||
: $event === $eventName;
|
||||
})
|
||||
->isNotEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Push the event onto the fake events array immediately or after the next database transaction.
|
||||
*
|
||||
* @param string|object $event
|
||||
* @param string $name
|
||||
* @param array $arguments
|
||||
* @return void
|
||||
*/
|
||||
protected function fakeEvent($event, $name, $arguments)
|
||||
{
|
||||
if ($event instanceof ShouldDispatchAfterCommit && Container::getInstance()->bound('db.transactions')) {
|
||||
return Container::getInstance()->make('db.transactions')
|
||||
->addCallback(fn () => $this->events[$name][] = $arguments);
|
||||
}
|
||||
|
||||
$this->events[$name][] = $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether an event should be dispatched or not.
|
||||
*
|
||||
* @param string $eventName
|
||||
* @param mixed $payload
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldDispatchEvent($eventName, $payload)
|
||||
{
|
||||
if (empty($this->eventsToDispatch)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (new Collection($this->eventsToDispatch))
|
||||
->filter(function ($event) use ($eventName, $payload) {
|
||||
return $event instanceof Closure
|
||||
? $event($eventName, $payload)
|
||||
: $event === $eventName;
|
||||
})
|
||||
->isNotEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a set of listeners from the dispatcher.
|
||||
*
|
||||
* @param string $event
|
||||
* @return void
|
||||
*/
|
||||
public function forget($event)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all of the queued listeners.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function forgetPushed()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch an event and call the listeners.
|
||||
*
|
||||
* @param string|object $event
|
||||
* @param mixed $payload
|
||||
* @return mixed
|
||||
*/
|
||||
public function until($event, $payload = [])
|
||||
{
|
||||
return $this->dispatch($event, $payload, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the events that have been dispatched.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dispatchedEvents()
|
||||
{
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dynamic method calls to the dispatcher.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->forwardCallTo($this->dispatcher, $method, $parameters);
|
||||
}
|
||||
}
|
||||
285
plugins/vendor/illuminate/support/Testing/Fakes/ExceptionHandlerFake.php
vendored
Normal file
285
plugins/vendor/illuminate/support/Testing/Fakes/ExceptionHandlerFake.php
vendored
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Foundation\Testing\Concerns\WithoutExceptionHandlingHandler;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Traits\ForwardsCalls;
|
||||
use Illuminate\Support\Traits\ReflectsClosures;
|
||||
use Illuminate\Testing\Assert;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @mixin \Illuminate\Foundation\Exceptions\Handler
|
||||
*/
|
||||
class ExceptionHandlerFake implements ExceptionHandler, Fake
|
||||
{
|
||||
use ForwardsCalls, ReflectsClosures;
|
||||
|
||||
/**
|
||||
* All of the exceptions that have been reported.
|
||||
*
|
||||
* @var list<\Throwable>
|
||||
*/
|
||||
protected $reported = [];
|
||||
|
||||
/**
|
||||
* If the fake should throw exceptions when they are reported.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $throwOnReport = false;
|
||||
|
||||
/**
|
||||
* Create a new exception handler fake.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Debug\ExceptionHandler $handler
|
||||
* @param list<class-string<\Throwable>> $exceptions
|
||||
*/
|
||||
public function __construct(
|
||||
protected ExceptionHandler $handler,
|
||||
protected array $exceptions = [],
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying handler implementation.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Debug\ExceptionHandler
|
||||
*/
|
||||
public function handler()
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if an exception of the given type has been reported.
|
||||
*
|
||||
* @param (\Closure(\Throwable): bool)|class-string<\Throwable> $exception
|
||||
* @return void
|
||||
*/
|
||||
public function assertReported(Closure|string $exception)
|
||||
{
|
||||
$message = sprintf(
|
||||
'The expected [%s] exception was not reported.',
|
||||
is_string($exception) ? $exception : $this->firstClosureParameterType($exception)
|
||||
);
|
||||
|
||||
if (is_string($exception)) {
|
||||
Assert::assertTrue(
|
||||
in_array($exception, array_map(get_class(...), $this->reported), true),
|
||||
$message,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Assert::assertTrue(
|
||||
(new Collection($this->reported))->contains(
|
||||
fn (Throwable $e) => $this->firstClosureParameterType($exception) === get_class($e)
|
||||
&& $exception($e) === true,
|
||||
), $message,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the number of exceptions that have been reported.
|
||||
*
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
public function assertReportedCount(int $count)
|
||||
{
|
||||
$total = (new Collection($this->reported))->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$count, $total,
|
||||
"The total number of exceptions reported was {$total} instead of {$count}."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if an exception of the given type has not been reported.
|
||||
*
|
||||
* @param (\Closure(\Throwable): bool)|class-string<\Throwable> $exception
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotReported(Closure|string $exception)
|
||||
{
|
||||
try {
|
||||
$this->assertReported($exception);
|
||||
} catch (ExpectationFailedException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new ExpectationFailedException(sprintf(
|
||||
'The expected [%s] exception was reported.',
|
||||
is_string($exception) ? $exception : $this->firstClosureParameterType($exception)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert nothing has been reported.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingReported()
|
||||
{
|
||||
Assert::assertEmpty(
|
||||
$this->reported,
|
||||
sprintf(
|
||||
'The following exceptions were reported: %s.',
|
||||
implode(', ', array_map(get_class(...), $this->reported)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
public function report($e)
|
||||
{
|
||||
if (! $this->isFakedException($e)) {
|
||||
$this->handler->report($e);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->shouldReport($e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reported[] = $e;
|
||||
|
||||
if ($this->throwOnReport) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given exception is faked.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return bool
|
||||
*/
|
||||
protected function isFakedException(Throwable $e)
|
||||
{
|
||||
return count($this->exceptions) === 0 || in_array(get_class($e), $this->exceptions, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the exception should be reported.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldReport($e)
|
||||
{
|
||||
return $this->runningWithoutExceptionHandling() || $this->handler->shouldReport($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the handler is running without exception handling.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function runningWithoutExceptionHandling()
|
||||
{
|
||||
return $this->handler instanceof WithoutExceptionHandlingHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $e
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function render($request, $e)
|
||||
{
|
||||
return $this->handler->render($request, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception to the console.
|
||||
*
|
||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
public function renderForConsole($output, Throwable $e)
|
||||
{
|
||||
$this->handler->renderForConsole($output, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw exceptions when they are reported.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function throwOnReport()
|
||||
{
|
||||
$this->throwOnReport = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw the first reported exception.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function throwFirstReported()
|
||||
{
|
||||
foreach ($this->reported as $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the exceptions that have been reported.
|
||||
*
|
||||
* @return list<\Throwable>
|
||||
*/
|
||||
public function reported()
|
||||
{
|
||||
return $this->reported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "original" handler that should be used by the fake.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Debug\ExceptionHandler $handler
|
||||
* @return $this
|
||||
*/
|
||||
public function setHandler(ExceptionHandler $handler)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dynamic method calls to the handler.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array<string, mixed> $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $method, array $parameters)
|
||||
{
|
||||
return $this->forwardCallTo($this->handler, $method, $parameters);
|
||||
}
|
||||
}
|
||||
8
plugins/vendor/illuminate/support/Testing/Fakes/Fake.php
vendored
Normal file
8
plugins/vendor/illuminate/support/Testing/Fakes/Fake.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
interface Fake
|
||||
{
|
||||
//
|
||||
}
|
||||
600
plugins/vendor/illuminate/support/Testing/Fakes/MailFake.php
vendored
Normal file
600
plugins/vendor/illuminate/support/Testing/Fakes/MailFake.php
vendored
Normal file
@@ -0,0 +1,600 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Mail\Factory;
|
||||
use Illuminate\Contracts\Mail\Mailable;
|
||||
use Illuminate\Contracts\Mail\Mailer;
|
||||
use Illuminate\Contracts\Mail\MailQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\MailManager;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Traits\ForwardsCalls;
|
||||
use Illuminate\Support\Traits\ReflectsClosures;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
|
||||
class MailFake implements Factory, Fake, Mailer, MailQueue
|
||||
{
|
||||
use ForwardsCalls, ReflectsClosures;
|
||||
|
||||
/**
|
||||
* The mailer instance.
|
||||
*
|
||||
* @var MailManager
|
||||
*/
|
||||
public $manager;
|
||||
|
||||
/**
|
||||
* The mailer currently being used to send a message.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentMailer;
|
||||
|
||||
/**
|
||||
* All of the mailables that have been sent.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mailables = [];
|
||||
|
||||
/**
|
||||
* All of the mailables that have been queued.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $queuedMailables = [];
|
||||
|
||||
/**
|
||||
* Create a new mail fake.
|
||||
*
|
||||
* @param MailManager $manager
|
||||
*/
|
||||
public function __construct(MailManager $manager)
|
||||
{
|
||||
$this->manager = $manager;
|
||||
$this->currentMailer = $manager->getDefaultDriver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a mailable was sent based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $mailable
|
||||
* @param callable|array|string|int|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertSent($mailable, $callback = null)
|
||||
{
|
||||
[$mailable, $callback] = $this->prepareMailableAndCallback($mailable, $callback);
|
||||
|
||||
if (is_numeric($callback)) {
|
||||
return $this->assertSentTimes($mailable, $callback);
|
||||
}
|
||||
|
||||
$suggestion = count($this->queuedMailables) ? ' Did you mean to use assertQueued() instead?' : '';
|
||||
|
||||
if (is_array($callback) || is_string($callback)) {
|
||||
foreach (Arr::wrap($callback) as $address) {
|
||||
$callback = fn ($mail) => $mail->hasTo($address);
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->sent($mailable, $callback)->count() > 0,
|
||||
"The expected [{$mailable}] mailable was not sent to address [{$address}].".$suggestion
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->sent($mailable, $callback)->count() > 0,
|
||||
"The expected [{$mailable}] mailable was not sent.".$suggestion
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a mailable was sent a number of times.
|
||||
*
|
||||
* @param string $mailable
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
protected function assertSentTimes($mailable, $times = 1)
|
||||
{
|
||||
$count = $this->sent($mailable)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$times, $count,
|
||||
sprintf(
|
||||
"The expected [{$mailable}] mailable was sent {$count} %s instead of {$times} %s.",
|
||||
Str::plural('time', $count),
|
||||
Str::plural('time', $times)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a mailable was not sent or queued to be sent based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $mailable
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotOutgoing($mailable, $callback = null)
|
||||
{
|
||||
$this->assertNotSent($mailable, $callback);
|
||||
$this->assertNotQueued($mailable, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a mailable was not sent based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $mailable
|
||||
* @param callable|array|string|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotSent($mailable, $callback = null)
|
||||
{
|
||||
if (is_string($callback) || is_array($callback)) {
|
||||
foreach (Arr::wrap($callback) as $address) {
|
||||
$callback = fn ($mail) => $mail->hasTo($address);
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->sent($mailable, $callback),
|
||||
"The unexpected [{$mailable}] mailable was sent to address [{$address}]."
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[$mailable, $callback] = $this->prepareMailableAndCallback($mailable, $callback);
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->sent($mailable, $callback),
|
||||
"The unexpected [{$mailable}] mailable was sent."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no mailables were sent or queued to be sent.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingOutgoing()
|
||||
{
|
||||
$this->assertNothingSent();
|
||||
$this->assertNothingQueued();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no mailables were sent.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingSent()
|
||||
{
|
||||
$mailableNames = (new Collection($this->mailables))->map(
|
||||
fn ($mailable) => get_class($mailable)
|
||||
)->join("\n- ");
|
||||
|
||||
PHPUnit::assertEmpty($this->mailables, "The following mailables were sent unexpectedly:\n\n- $mailableNames\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a mailable was queued based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $mailable
|
||||
* @param callable|array|string|int|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertQueued($mailable, $callback = null)
|
||||
{
|
||||
[$mailable, $callback] = $this->prepareMailableAndCallback($mailable, $callback);
|
||||
|
||||
if (is_numeric($callback)) {
|
||||
return $this->assertQueuedTimes($mailable, $callback);
|
||||
}
|
||||
|
||||
if (is_string($callback) || is_array($callback)) {
|
||||
foreach (Arr::wrap($callback) as $address) {
|
||||
$callback = fn ($mail) => $mail->hasTo($address);
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->queued($mailable, $callback)->count() > 0,
|
||||
"The expected [{$mailable}] mailable was not queued to address [{$address}]."
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->queued($mailable, $callback)->count() > 0,
|
||||
"The expected [{$mailable}] mailable was not queued."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a mailable was queued a number of times.
|
||||
*
|
||||
* @param string $mailable
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
protected function assertQueuedTimes($mailable, $times = 1)
|
||||
{
|
||||
$count = $this->queued($mailable)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$times, $count,
|
||||
sprintf(
|
||||
"The expected [{$mailable}] mailable was queued {$count} %s instead of {$times} %s.",
|
||||
Str::plural('time', $count),
|
||||
Str::plural('time', $times)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a mailable was not queued based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $mailable
|
||||
* @param callable|array|string|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotQueued($mailable, $callback = null)
|
||||
{
|
||||
if (is_string($callback) || is_array($callback)) {
|
||||
foreach (Arr::wrap($callback) as $address) {
|
||||
$callback = fn ($mail) => $mail->hasTo($address);
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->queued($mailable, $callback),
|
||||
"The unexpected [{$mailable}] mailable was queued to address [{$address}]."
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[$mailable, $callback] = $this->prepareMailableAndCallback($mailable, $callback);
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->queued($mailable, $callback),
|
||||
"The unexpected [{$mailable}] mailable was queued."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no mailables were queued.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingQueued()
|
||||
{
|
||||
$mailableNames = (new Collection($this->queuedMailables))->map(
|
||||
fn ($mailable) => get_class($mailable)
|
||||
)->join("\n- ");
|
||||
|
||||
PHPUnit::assertEmpty($this->queuedMailables, "The following mailables were queued unexpectedly:\n\n- $mailableNames\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the total number of mailables that were sent.
|
||||
*
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
public function assertSentCount($count)
|
||||
{
|
||||
$total = (new Collection($this->mailables))->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$count, $total,
|
||||
"The total number of mailables sent was {$total} instead of {$count}."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the total number of mailables that were queued.
|
||||
*
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
public function assertQueuedCount($count)
|
||||
{
|
||||
$total = (new Collection($this->queuedMailables))->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$count, $total,
|
||||
"The total number of mailables queued was {$total} instead of {$count}."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the total number of mailables that were sent or queued.
|
||||
*
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
public function assertOutgoingCount($count)
|
||||
{
|
||||
$total = (new Collection($this->mailables))
|
||||
->concat($this->queuedMailables)
|
||||
->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$count, $total,
|
||||
"The total number of outgoing mailables was {$total} instead of {$count}."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the mailables matching a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $mailable
|
||||
* @param callable|null $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function sent($mailable, $callback = null)
|
||||
{
|
||||
[$mailable, $callback] = $this->prepareMailableAndCallback($mailable, $callback);
|
||||
|
||||
if (! $this->hasSent($mailable)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$callback = $callback ?: fn () => true;
|
||||
|
||||
return $this->mailablesOf($mailable)->filter(fn ($mailable) => $callback($mailable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given mailable has been sent.
|
||||
*
|
||||
* @param string $mailable
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSent($mailable)
|
||||
{
|
||||
return $this->mailablesOf($mailable)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the queued mailables matching a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $mailable
|
||||
* @param callable|null $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function queued($mailable, $callback = null)
|
||||
{
|
||||
[$mailable, $callback] = $this->prepareMailableAndCallback($mailable, $callback);
|
||||
|
||||
if (! $this->hasQueued($mailable)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$callback = $callback ?: fn () => true;
|
||||
|
||||
return $this->queuedMailablesOf($mailable)->filter(fn ($mailable) => $callback($mailable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given mailable has been queued.
|
||||
*
|
||||
* @param string $mailable
|
||||
* @return bool
|
||||
*/
|
||||
public function hasQueued($mailable)
|
||||
{
|
||||
return $this->queuedMailablesOf($mailable)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the mailed mailables for a given type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected function mailablesOf($type)
|
||||
{
|
||||
return (new Collection($this->mailables))->filter(fn ($mailable) => $mailable instanceof $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the mailed mailables for a given type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected function queuedMailablesOf($type)
|
||||
{
|
||||
return (new Collection($this->queuedMailables))->filter(fn ($mailable) => $mailable instanceof $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mailer instance by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return \Illuminate\Contracts\Mail\Mailer
|
||||
*/
|
||||
public function mailer($name = null)
|
||||
{
|
||||
$this->currentMailer = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin the process of mailing a mailable class instance.
|
||||
*
|
||||
* @param mixed $users
|
||||
* @return \Illuminate\Mail\PendingMail
|
||||
*/
|
||||
public function to($users)
|
||||
{
|
||||
return (new PendingMailFake($this))->to($users);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin the process of mailing a mailable class instance.
|
||||
*
|
||||
* @param mixed $users
|
||||
* @return \Illuminate\Mail\PendingMail
|
||||
*/
|
||||
public function cc($users)
|
||||
{
|
||||
return (new PendingMailFake($this))->cc($users);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin the process of mailing a mailable class instance.
|
||||
*
|
||||
* @param mixed $users
|
||||
* @return \Illuminate\Mail\PendingMail
|
||||
*/
|
||||
public function bcc($users)
|
||||
{
|
||||
return (new PendingMailFake($this))->bcc($users);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new message with only a raw text part.
|
||||
*
|
||||
* @param string $text
|
||||
* @param \Closure|string $callback
|
||||
* @return void
|
||||
*/
|
||||
public function raw($text, $callback)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new message using a view.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailable|string|array $view
|
||||
* @param array $data
|
||||
* @param \Closure|string|null $callback
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function send($view, array $data = [], $callback = null)
|
||||
{
|
||||
return $this->sendMail($view, $view instanceof ShouldQueue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new message synchronously using a view.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailable|string|array $mailable
|
||||
* @param array $data
|
||||
* @param \Closure|string|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function sendNow($mailable, array $data = [], $callback = null)
|
||||
{
|
||||
$this->sendMail($mailable, shouldQueue: false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new message using a view.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailable|string|array $view
|
||||
* @param bool $shouldQueue
|
||||
* @return mixed|void
|
||||
*/
|
||||
protected function sendMail($view, $shouldQueue = false)
|
||||
{
|
||||
if (! $view instanceof Mailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
$view->mailer($this->currentMailer);
|
||||
|
||||
if ($shouldQueue) {
|
||||
return $this->queue($view);
|
||||
}
|
||||
|
||||
$this->currentMailer = null;
|
||||
|
||||
$this->mailables[] = $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a new message for sending.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailable|string|array $view
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function queue($view, $queue = null)
|
||||
{
|
||||
if (! $view instanceof Mailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
$view->mailer($this->currentMailer);
|
||||
|
||||
$this->currentMailer = null;
|
||||
|
||||
$this->queuedMailables[] = $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a new e-mail message for sending after (n) seconds.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param \Illuminate\Contracts\Mail\Mailable|string|array $view
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function later($delay, $view, $queue = null)
|
||||
{
|
||||
$this->queue($view, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Infer mailable class using reflection if a typehinted closure is passed to assertion.
|
||||
*
|
||||
* @param string|\Closure $mailable
|
||||
* @param callable|null $callback
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareMailableAndCallback($mailable, $callback)
|
||||
{
|
||||
if ($mailable instanceof Closure) {
|
||||
return [$this->firstClosureParameterType($mailable), $mailable];
|
||||
}
|
||||
|
||||
return [$mailable, $callback];
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget all of the resolved mailer instances.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function forgetMailers()
|
||||
{
|
||||
$this->currentMailer = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dynamic method calls to the mailer.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->forwardCallTo($this->manager, $method, $parameters);
|
||||
}
|
||||
}
|
||||
405
plugins/vendor/illuminate/support/Testing/Fakes/NotificationFake.php
vendored
Normal file
405
plugins/vendor/illuminate/support/Testing/Fakes/NotificationFake.php
vendored
Normal file
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Notifications\Dispatcher as NotificationDispatcher;
|
||||
use Illuminate\Contracts\Notifications\Factory as NotificationFactory;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Contracts\Translation\HasLocalePreference;
|
||||
use Illuminate\Notifications\AnonymousNotifiable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use Illuminate\Support\Traits\ReflectsClosures;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
|
||||
class NotificationFake implements Fake, NotificationDispatcher, NotificationFactory
|
||||
{
|
||||
use Macroable, ReflectsClosures;
|
||||
|
||||
/**
|
||||
* All of the notifications that have been sent.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $notifications = [];
|
||||
|
||||
/**
|
||||
* Locale used when sending notifications.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $locale;
|
||||
|
||||
/**
|
||||
* Indicates if notifications should be serialized and restored when pushed to the queue.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $serializeAndRestore = false;
|
||||
|
||||
/**
|
||||
* Assert if a notification was sent on-demand based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $notification
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function assertSentOnDemand($notification, $callback = null)
|
||||
{
|
||||
$this->assertSentTo(new AnonymousNotifiable, $notification, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a notification was sent based on a truth-test callback.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @param string|\Closure $notification
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function assertSentTo($notifiable, $notification, $callback = null)
|
||||
{
|
||||
if (is_array($notifiable) || $notifiable instanceof Collection) {
|
||||
if (count($notifiable) === 0) {
|
||||
throw new Exception('No notifiable given.');
|
||||
}
|
||||
|
||||
foreach ($notifiable as $singleNotifiable) {
|
||||
$this->assertSentTo($singleNotifiable, $notification, $callback);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($notification instanceof Closure) {
|
||||
[$notification, $callback] = [$this->firstClosureParameterType($notification), $notification];
|
||||
}
|
||||
|
||||
if (is_numeric($callback)) {
|
||||
return $this->assertSentToTimes($notifiable, $notification, $callback);
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->sent($notifiable, $notification, $callback)->count() > 0,
|
||||
"The expected [{$notification}] notification was not sent."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a notification was sent on-demand a number of times.
|
||||
*
|
||||
* @param string $notification
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
public function assertSentOnDemandTimes($notification, $times = 1)
|
||||
{
|
||||
$this->assertSentToTimes(new AnonymousNotifiable, $notification, $times);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a notification was sent a number of times.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @param string $notification
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
public function assertSentToTimes($notifiable, $notification, $times = 1)
|
||||
{
|
||||
$count = $this->sent($notifiable, $notification)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$times, $count,
|
||||
"Expected [{$notification}] to be sent {$times} times, but was sent {$count} times."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a notification was sent based on a truth-test callback.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @param string|\Closure $notification
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function assertNotSentTo($notifiable, $notification, $callback = null)
|
||||
{
|
||||
if (is_array($notifiable) || $notifiable instanceof Collection) {
|
||||
if (count($notifiable) === 0) {
|
||||
throw new Exception('No notifiable given.');
|
||||
}
|
||||
|
||||
foreach ($notifiable as $singleNotifiable) {
|
||||
$this->assertNotSentTo($singleNotifiable, $notification, $callback);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($notification instanceof Closure) {
|
||||
[$notification, $callback] = [$this->firstClosureParameterType($notification), $notification];
|
||||
}
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->sent($notifiable, $notification, $callback),
|
||||
"The unexpected [{$notification}] notification was sent."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no notifications were sent.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingSent()
|
||||
{
|
||||
$notificationNames = (new Collection($this->notifications))
|
||||
->map(fn ($notifiableModels) => (new Collection($notifiableModels))
|
||||
->map(fn ($notifiables) => (new Collection($notifiables))->keys())
|
||||
)
|
||||
->flatten()->join("\n- ");
|
||||
|
||||
PHPUnit::assertEmpty($this->notifications, "The following notifications were sent unexpectedly:\n\n- $notificationNames\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no notifications were sent to the given notifiable.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function assertNothingSentTo($notifiable)
|
||||
{
|
||||
if (is_array($notifiable) || $notifiable instanceof Collection) {
|
||||
if (count($notifiable) === 0) {
|
||||
throw new Exception('No notifiable given.');
|
||||
}
|
||||
|
||||
foreach ($notifiable as $singleNotifiable) {
|
||||
$this->assertNothingSentTo($singleNotifiable);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PHPUnit::assertEmpty(
|
||||
$this->notifications[get_class($notifiable)][$notifiable->getKey()] ?? [],
|
||||
'Notifications were sent unexpectedly.',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the total amount of times a notification was sent.
|
||||
*
|
||||
* @param string $notification
|
||||
* @param int $expectedCount
|
||||
* @return void
|
||||
*/
|
||||
public function assertSentTimes($notification, $expectedCount)
|
||||
{
|
||||
$actualCount = (new Collection($this->notifications))
|
||||
->flatten(1)
|
||||
->reduce(fn ($count, $sent) => $count + count($sent[$notification] ?? []), 0);
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$expectedCount, $actualCount,
|
||||
sprintf(
|
||||
"Expected [{$notification}] to be sent {$expectedCount} %s, but was sent {$actualCount} %s.",
|
||||
Str::plural('time', $expectedCount),
|
||||
Str::plural('time', $actualCount)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the total count of notification that were sent.
|
||||
*
|
||||
* @param int $expectedCount
|
||||
* @return void
|
||||
*/
|
||||
public function assertCount($expectedCount)
|
||||
{
|
||||
$actualCount = (new Collection($this->notifications))->flatten(3)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$expectedCount, $actualCount,
|
||||
"Expected {$expectedCount} notifications to be sent, but {$actualCount} were sent."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the notifications matching a truth-test callback.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @param string $notification
|
||||
* @param callable|null $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function sent($notifiable, $notification, $callback = null)
|
||||
{
|
||||
if (! $this->hasSent($notifiable, $notification)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$callback = $callback ?: fn () => true;
|
||||
|
||||
$notifications = new Collection($this->notificationsFor($notifiable, $notification));
|
||||
|
||||
return $notifications->filter(
|
||||
fn ($arguments) => $callback(...array_values($arguments))
|
||||
)->pluck('notification');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are more notifications left to inspect.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @param string $notification
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSent($notifiable, $notification)
|
||||
{
|
||||
return ! empty($this->notificationsFor($notifiable, $notification));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the notifications for a notifiable entity by type.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @param string $notification
|
||||
* @return array
|
||||
*/
|
||||
protected function notificationsFor($notifiable, $notification)
|
||||
{
|
||||
return $this->notifications[get_class($notifiable)][(string) $notifiable->getKey()][$notification] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the given notification to the given notifiable entities.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|mixed $notifiables
|
||||
* @param mixed $notification
|
||||
* @return void
|
||||
*/
|
||||
public function send($notifiables, $notification)
|
||||
{
|
||||
$this->sendNow($notifiables, $notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the given notification immediately.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|mixed $notifiables
|
||||
* @param mixed $notification
|
||||
* @param array|null $channels
|
||||
* @return void
|
||||
*/
|
||||
public function sendNow($notifiables, $notification, ?array $channels = null)
|
||||
{
|
||||
if (! $notifiables instanceof Collection && ! is_array($notifiables)) {
|
||||
$notifiables = [$notifiables];
|
||||
}
|
||||
|
||||
foreach ($notifiables as $notifiable) {
|
||||
if (! $notification->id) {
|
||||
$notification->id = Str::uuid()->toString();
|
||||
}
|
||||
|
||||
$notifiableChannels = $channels ?: $notification->via($notifiable);
|
||||
|
||||
if (method_exists($notification, 'shouldSend')) {
|
||||
$notifiableChannels = array_filter(
|
||||
$notifiableChannels,
|
||||
fn ($channel) => $notification->shouldSend($notifiable, $channel) !== false
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($notifiableChannels)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->notifications[get_class($notifiable)][(string) $notifiable->getKey()][get_class($notification)][] = [
|
||||
'notification' => $this->serializeAndRestore && $notification instanceof ShouldQueue
|
||||
? $this->serializeAndRestoreNotification($notification)
|
||||
: $notification,
|
||||
'channels' => $notifiableChannels,
|
||||
'notifiable' => $notifiable,
|
||||
'locale' => $notification->locale ?? $this->locale ?? value(function () use ($notifiable) {
|
||||
if ($notifiable instanceof HasLocalePreference) {
|
||||
return $notifiable->preferredLocale();
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a channel instance by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function channel($name = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locale of notifications.
|
||||
*
|
||||
* @param string $locale
|
||||
* @return $this
|
||||
*/
|
||||
public function locale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if notification should be serialized and restored when being "pushed" to the queue.
|
||||
*
|
||||
* @param bool $serializeAndRestore
|
||||
* @return $this
|
||||
*/
|
||||
public function serializeAndRestore(bool $serializeAndRestore = true)
|
||||
{
|
||||
$this->serializeAndRestore = $serializeAndRestore;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize and unserialize the notification to simulate the queueing process.
|
||||
*
|
||||
* @param mixed $notification
|
||||
* @return mixed
|
||||
*/
|
||||
protected function serializeAndRestoreNotification($notification)
|
||||
{
|
||||
return unserialize(serialize($notification));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notifications that have been sent.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sentNotifications()
|
||||
{
|
||||
return $this->notifications;
|
||||
}
|
||||
}
|
||||
48
plugins/vendor/illuminate/support/Testing/Fakes/PendingBatchFake.php
vendored
Normal file
48
plugins/vendor/illuminate/support/Testing/Fakes/PendingBatchFake.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PendingBatchFake extends PendingBatch
|
||||
{
|
||||
/**
|
||||
* The fake bus instance.
|
||||
*
|
||||
* @var \Illuminate\Support\Testing\Fakes\BusFake
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
/**
|
||||
* Create a new pending batch instance.
|
||||
*
|
||||
* @param \Illuminate\Support\Testing\Fakes\BusFake $bus
|
||||
* @param \Illuminate\Support\Collection $jobs
|
||||
*/
|
||||
public function __construct(BusFake $bus, Collection $jobs)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
$this->jobs = $jobs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the batch.
|
||||
*
|
||||
* @return \Illuminate\Bus\Batch
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
return $this->bus->recordPendingBatch($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the batch after the response is sent to the browser.
|
||||
*
|
||||
* @return \Illuminate\Bus\Batch
|
||||
*/
|
||||
public function dispatchAfterResponse()
|
||||
{
|
||||
return $this->bus->recordPendingBatch($this);
|
||||
}
|
||||
}
|
||||
55
plugins/vendor/illuminate/support/Testing/Fakes/PendingChainFake.php
vendored
Normal file
55
plugins/vendor/illuminate/support/Testing/Fakes/PendingChainFake.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Foundation\Bus\PendingChain;
|
||||
use Illuminate\Queue\CallQueuedClosure;
|
||||
|
||||
class PendingChainFake extends PendingChain
|
||||
{
|
||||
/**
|
||||
* The fake bus instance.
|
||||
*
|
||||
* @var \Illuminate\Support\Testing\Fakes\BusFake
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
/**
|
||||
* Create a new pending chain instance.
|
||||
*
|
||||
* @param \Illuminate\Support\Testing\Fakes\BusFake $bus
|
||||
* @param mixed $job
|
||||
* @param array $chain
|
||||
*/
|
||||
public function __construct(BusFake $bus, $job, $chain)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
$this->job = $job;
|
||||
$this->chain = $chain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the job with the given arguments.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Bus\PendingDispatch
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
if (is_string($this->job)) {
|
||||
$firstJob = new $this->job(...func_get_args());
|
||||
} elseif ($this->job instanceof Closure) {
|
||||
$firstJob = CallQueuedClosure::create($this->job);
|
||||
} else {
|
||||
$firstJob = $this->job;
|
||||
}
|
||||
|
||||
$firstJob->allOnConnection($this->connection);
|
||||
$firstJob->allOnQueue($this->queue);
|
||||
$firstJob->chain($this->chain);
|
||||
$firstJob->delay($this->delay);
|
||||
$firstJob->chainCatchCallbacks = $this->catchCallbacks();
|
||||
|
||||
return $this->bus->dispatch($firstJob);
|
||||
}
|
||||
}
|
||||
52
plugins/vendor/illuminate/support/Testing/Fakes/PendingMailFake.php
vendored
Normal file
52
plugins/vendor/illuminate/support/Testing/Fakes/PendingMailFake.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use Illuminate\Contracts\Mail\Mailable;
|
||||
use Illuminate\Mail\PendingMail;
|
||||
|
||||
class PendingMailFake extends PendingMail
|
||||
{
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param \Illuminate\Support\Testing\Fakes\MailFake $mailer
|
||||
*/
|
||||
public function __construct($mailer)
|
||||
{
|
||||
$this->mailer = $mailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new mailable message instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailable $mailable
|
||||
* @return void
|
||||
*/
|
||||
public function send(Mailable $mailable)
|
||||
{
|
||||
$this->mailer->send($this->fill($mailable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new mailable message instance synchronously.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailable $mailable
|
||||
* @return void
|
||||
*/
|
||||
public function sendNow(Mailable $mailable)
|
||||
{
|
||||
$this->mailer->sendNow($this->fill($mailable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Push the given mailable onto the queue.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailable $mailable
|
||||
* @return mixed
|
||||
*/
|
||||
public function queue(Mailable $mailable)
|
||||
{
|
||||
return $this->mailer->queue($this->fill($mailable));
|
||||
}
|
||||
}
|
||||
689
plugins/vendor/illuminate/support/Testing/Fakes/QueueFake.php
vendored
Normal file
689
plugins/vendor/illuminate/support/Testing/Fakes/QueueFake.php
vendored
Normal file
@@ -0,0 +1,689 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Testing\Fakes;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Queue\Queue;
|
||||
use Illuminate\Events\CallQueuedListener;
|
||||
use Illuminate\Queue\CallQueuedClosure;
|
||||
use Illuminate\Queue\QueueManager;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Traits\ReflectsClosures;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
|
||||
/**
|
||||
* @phpstan-type RawPushType array{"payload": string, "queue": string|null, "options": array<array-key, mixed>}
|
||||
*/
|
||||
class QueueFake extends QueueManager implements Fake, Queue
|
||||
{
|
||||
use ReflectsClosures;
|
||||
|
||||
/**
|
||||
* The original queue manager.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public $queue;
|
||||
|
||||
/**
|
||||
* The job types that should be intercepted instead of pushed to the queue.
|
||||
*
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $jobsToFake;
|
||||
|
||||
/**
|
||||
* The job types that should be pushed to the queue and not intercepted.
|
||||
*
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $jobsToBeQueued;
|
||||
|
||||
/**
|
||||
* All of the jobs that have been pushed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $jobs = [];
|
||||
|
||||
/**
|
||||
* All of the payloads that have been raw pushed.
|
||||
*
|
||||
* @var list<RawPushType>
|
||||
*/
|
||||
protected $rawPushes = [];
|
||||
|
||||
/**
|
||||
* Indicates if items should be serialized and restored when pushed to the queue.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $serializeAndRestore = false;
|
||||
|
||||
/**
|
||||
* Create a new fake queue instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @param array $jobsToFake
|
||||
* @param \Illuminate\Queue\QueueManager|null $queue
|
||||
*/
|
||||
public function __construct($app, $jobsToFake = [], $queue = null)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
$this->jobsToFake = Collection::wrap($jobsToFake);
|
||||
$this->jobsToBeQueued = new Collection;
|
||||
$this->queue = $queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the jobs that should be queued instead of faked.
|
||||
*
|
||||
* @param array|string $jobsToBeQueued
|
||||
* @return $this
|
||||
*/
|
||||
public function except($jobsToBeQueued)
|
||||
{
|
||||
$this->jobsToBeQueued = Collection::wrap($jobsToBeQueued)->merge($this->jobsToBeQueued);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $job
|
||||
* @param callable|int|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertPushed($job, $callback = null)
|
||||
{
|
||||
if ($job instanceof Closure) {
|
||||
[$job, $callback] = [$this->firstClosureParameterType($job), $job];
|
||||
}
|
||||
|
||||
if (is_numeric($callback)) {
|
||||
return $this->assertPushedTimes($job, $callback);
|
||||
}
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->pushed($job, $callback)->count() > 0,
|
||||
"The expected [{$job}] job was not pushed."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed a number of times.
|
||||
*
|
||||
* @param string $job
|
||||
* @param int $times
|
||||
* @return void
|
||||
*/
|
||||
protected function assertPushedTimes($job, $times = 1)
|
||||
{
|
||||
$count = $this->pushed($job)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$times, $count,
|
||||
sprintf(
|
||||
"The expected [{$job}] job was pushed {$count} %s instead of {$times} %s.",
|
||||
Str::plural('time', $count),
|
||||
Str::plural('time', $times)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed based on a truth-test callback.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param string|\Closure $job
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertPushedOn($queue, $job, $callback = null)
|
||||
{
|
||||
if ($job instanceof Closure) {
|
||||
[$job, $callback] = [$this->firstClosureParameterType($job), $job];
|
||||
}
|
||||
|
||||
$this->assertPushed($job, function ($job, $pushedQueue) use ($callback, $queue) {
|
||||
if ($pushedQueue !== $queue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $callback ? $callback(...func_get_args()) : true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed with chained jobs based on a truth-test callback.
|
||||
*
|
||||
* @param string $job
|
||||
* @param array $expectedChain
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertPushedWithChain($job, $expectedChain = [], $callback = null)
|
||||
{
|
||||
PHPUnit::assertTrue(
|
||||
$this->pushed($job, $callback)->isNotEmpty(),
|
||||
"The expected [{$job}] job was not pushed."
|
||||
);
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
(new Collection($expectedChain))->isNotEmpty(),
|
||||
'The expected chain can not be empty.'
|
||||
);
|
||||
|
||||
$this->isChainOfObjects($expectedChain)
|
||||
? $this->assertPushedWithChainOfObjects($job, $expectedChain, $callback)
|
||||
: $this->assertPushedWithChainOfClasses($job, $expectedChain, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed with an empty chain based on a truth-test callback.
|
||||
*
|
||||
* @param string $job
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertPushedWithoutChain($job, $callback = null)
|
||||
{
|
||||
PHPUnit::assertTrue(
|
||||
$this->pushed($job, $callback)->isNotEmpty(),
|
||||
"The expected [{$job}] job was not pushed."
|
||||
);
|
||||
|
||||
$this->assertPushedWithChainOfClasses($job, [], $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed with chained jobs based on a truth-test callback.
|
||||
*
|
||||
* @param string $job
|
||||
* @param array $expectedChain
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
protected function assertPushedWithChainOfObjects($job, $expectedChain, $callback)
|
||||
{
|
||||
$chain = (new Collection($expectedChain))->map(fn ($job) => serialize($job))->all();
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$this->pushed($job, $callback)->filter(fn ($job) => $job->chained == $chain)->isNotEmpty(),
|
||||
'The expected chain was not pushed.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a job was pushed with chained jobs based on a truth-test callback.
|
||||
*
|
||||
* @param string $job
|
||||
* @param array $expectedChain
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
protected function assertPushedWithChainOfClasses($job, $expectedChain, $callback)
|
||||
{
|
||||
$matching = $this->pushed($job, $callback)->map->chained->map(function ($chain) {
|
||||
return (new Collection($chain))->map(function ($job) {
|
||||
return get_class(unserialize($job));
|
||||
});
|
||||
})->filter(function ($chain) use ($expectedChain) {
|
||||
return $chain->all() === $expectedChain;
|
||||
});
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
$matching->isNotEmpty(), 'The expected chain was not pushed.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert if a closure was pushed based on a truth-test callback.
|
||||
*
|
||||
* @param callable|int|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertClosurePushed($callback = null)
|
||||
{
|
||||
$this->assertPushed(CallQueuedClosure::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that a closure was not pushed based on a truth-test callback.
|
||||
*
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertClosureNotPushed($callback = null)
|
||||
{
|
||||
$this->assertNotPushed(CallQueuedClosure::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given chain is entirely composed of objects.
|
||||
*
|
||||
* @param array $chain
|
||||
* @return bool
|
||||
*/
|
||||
protected function isChainOfObjects($chain)
|
||||
{
|
||||
return ! (new Collection($chain))->contains(fn ($job) => ! is_object($job));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a job was pushed based on a truth-test callback.
|
||||
*
|
||||
* @param string|\Closure $job
|
||||
* @param callable|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function assertNotPushed($job, $callback = null)
|
||||
{
|
||||
if ($job instanceof Closure) {
|
||||
[$job, $callback] = [$this->firstClosureParameterType($job), $job];
|
||||
}
|
||||
|
||||
PHPUnit::assertCount(
|
||||
0, $this->pushed($job, $callback),
|
||||
"The unexpected [{$job}] job was pushed."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the total count of jobs that were pushed.
|
||||
*
|
||||
* @param int $expectedCount
|
||||
* @return void
|
||||
*/
|
||||
public function assertCount($expectedCount)
|
||||
{
|
||||
$actualCount = (new Collection($this->jobs))->flatten(1)->count();
|
||||
|
||||
PHPUnit::assertSame(
|
||||
$expectedCount, $actualCount,
|
||||
"Expected {$expectedCount} jobs to be pushed, but found {$actualCount} instead."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that no jobs were pushed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function assertNothingPushed()
|
||||
{
|
||||
$pushedJobs = implode("\n- ", array_keys($this->jobs));
|
||||
|
||||
PHPUnit::assertEmpty($this->jobs, "The following jobs were pushed unexpectedly:\n\n- $pushedJobs\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the jobs matching a truth-test callback.
|
||||
*
|
||||
* @param string $job
|
||||
* @param callable|null $callback
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function pushed($job, $callback = null)
|
||||
{
|
||||
if (! $this->hasPushed($job)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$callback = $callback ?: fn () => true;
|
||||
|
||||
return (new Collection($this->jobs[$job]))->filter(
|
||||
fn ($data) => $callback($data['job'], $data['queue'], $data['data'])
|
||||
)->pluck('job');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the raw pushes matching a truth-test callback.
|
||||
*
|
||||
* @param null|\Closure(string, ?string, array): bool $callback
|
||||
* @return \Illuminate\Support\Collection<int, RawPushType>
|
||||
*/
|
||||
public function pushedRaw($callback = null)
|
||||
{
|
||||
$callback ??= static fn () => true;
|
||||
|
||||
return (new Collection($this->rawPushes))->filter(fn ($data) => $callback($data['payload'], $data['queue'], $data['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the jobs by listener class, passing an optional truth-test callback.
|
||||
*
|
||||
* @param class-string $listenerClass
|
||||
* @param (\Closure(mixed, \Illuminate\Events\CallQueuedListener, string|null, mixed): bool)|null $callback
|
||||
* @return \Illuminate\Support\Collection<int, \Illuminate\Events\CallQueuedListener>
|
||||
*/
|
||||
public function listenersPushed($listenerClass, $callback = null)
|
||||
{
|
||||
if (! $this->hasPushed(CallQueuedListener::class)) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
$collection = (new Collection($this->jobs[CallQueuedListener::class]))
|
||||
->filter(fn ($data) => $data['job']->class === $listenerClass);
|
||||
|
||||
if ($callback) {
|
||||
$collection = $collection->filter(fn ($data) => $callback($data['job']->data[0] ?? null, $data['job'], $data['queue'], $data['data']));
|
||||
}
|
||||
|
||||
return $collection->pluck('job');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are any stored jobs for a given class.
|
||||
*
|
||||
* @param string $job
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPushed($job)
|
||||
{
|
||||
return isset($this->jobs[$job]) && ! empty($this->jobs[$job]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a queue connection instance.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connection($value = null)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function size($queue = null)
|
||||
{
|
||||
return (new Collection($this->jobs))
|
||||
->flatten(1)
|
||||
->filter(fn ($job) => $job['queue'] === $queue)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of pending jobs.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function pendingSize($queue = null)
|
||||
{
|
||||
return $this->size($queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of delayed jobs.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function delayedSize($queue = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of reserved jobs.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function reservedSize($queue = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the creation timestamp of the oldest pending job, excluding delayed jobs.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int|null
|
||||
*/
|
||||
public function creationTimeOfOldestPendingJob($queue = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string|object $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function push($job, $data = '', $queue = null)
|
||||
{
|
||||
if ($this->shouldFakeJob($job)) {
|
||||
if ($job instanceof Closure) {
|
||||
$job = CallQueuedClosure::create($job);
|
||||
}
|
||||
|
||||
$this->jobs[is_object($job) ? get_class($job) : $job][] = [
|
||||
'job' => $this->serializeAndRestore ? $this->serializeAndRestoreJob($job) : $job,
|
||||
'queue' => $queue,
|
||||
'data' => $data,
|
||||
];
|
||||
} else {
|
||||
is_object($job) && isset($job->connection)
|
||||
? $this->queue->connection($job->connection)->push($job, $data, $queue)
|
||||
: $this->queue->push($job, $data, $queue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a job should be faked or actually dispatched.
|
||||
*
|
||||
* @param object $job
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldFakeJob($job)
|
||||
{
|
||||
if ($this->shouldDispatchJob($job)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->jobsToFake->isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->jobsToFake->contains(
|
||||
fn ($jobToFake) => $job instanceof ((string) $jobToFake) || $job === (string) $jobToFake
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a job should be pushed to the queue instead of faked.
|
||||
*
|
||||
* @param object $job
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldDispatchJob($job)
|
||||
{
|
||||
if ($this->jobsToBeQueued->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->jobsToBeQueued->contains(
|
||||
fn ($jobToQueue) => $job instanceof ((string) $jobToQueue)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw payload onto the queue.
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushRaw($payload, $queue = null, array $options = [])
|
||||
{
|
||||
$this->rawPushes[] = [
|
||||
'payload' => $payload,
|
||||
'queue' => $queue,
|
||||
'options' => $options,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after (n) seconds.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string|object $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function later($delay, $job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->push($job, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param string|object $job
|
||||
* @param mixed $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushOn($queue, $job, $data = '')
|
||||
{
|
||||
return $this->push($job, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto a specific queue after (n) seconds.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string|object $job
|
||||
* @param mixed $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function laterOn($queue, $delay, $job, $data = '')
|
||||
{
|
||||
return $this->push($job, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the next job off of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return \Illuminate\Contracts\Queue\Job|null
|
||||
*/
|
||||
public function pop($queue = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an array of jobs onto the queue.
|
||||
*
|
||||
* @param array $jobs
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function bulk($jobs, $data = '', $queue = null)
|
||||
{
|
||||
foreach ($jobs as $job) {
|
||||
$this->push($job, $data, $queue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the jobs that have been pushed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pushedJobs()
|
||||
{
|
||||
return $this->jobs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payloads that were pushed raw.
|
||||
*
|
||||
* @return list<RawPushType>
|
||||
*/
|
||||
public function rawPushes()
|
||||
{
|
||||
return $this->rawPushes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if jobs should be serialized and restored when being "pushed" to the queue.
|
||||
*
|
||||
* @param bool $serializeAndRestore
|
||||
* @return $this
|
||||
*/
|
||||
public function serializeAndRestore(bool $serializeAndRestore = true)
|
||||
{
|
||||
$this->serializeAndRestore = $serializeAndRestore;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize and unserialize the job to simulate the queueing process.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @return mixed
|
||||
*/
|
||||
protected function serializeAndRestoreJob($job)
|
||||
{
|
||||
return unserialize(serialize($job));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection name for the queue.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConnectionName()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the connection name for the queue.
|
||||
*
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnectionName($name)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the QueueManager to prevent circular dependency.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
throw new BadMethodCallException(sprintf(
|
||||
'Call to undefined method %s::%s()', static::class, $method
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user