• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tochka-developers / queue-promises / 9935584685

15 Jul 2024 07:44AM UTC coverage: 47.259% (-18.3%) from 65.524%
9935584685

push

github

darkdarin
fix: tests

4 of 4 new or added lines in 2 files covered. (100.0%)

431 existing lines in 40 files now uncovered.

612 of 1295 relevant lines covered (47.26%)

2.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Registry/PromiseJobRegistry.php
1
<?php
2

3
namespace Tochka\Promises\Registry;
4

5
use Illuminate\Database\Eloquent\ModelNotFoundException;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\LazyCollection;
8
use Tochka\Promises\Core\BaseJob;
9
use Tochka\Promises\Models\PromiseJob;
10

11
class PromiseJobRegistry implements PromiseJobRegistryInterface
12
{
13
    public function load(int $id): BaseJob
14
    {
UNCOV
15
        $jobModel = PromiseJob::find($id);
×
UNCOV
16
        if (!$jobModel) {
×
UNCOV
17
            throw (new ModelNotFoundException())->setModel(PromiseJob::class, $id);
×
18
        }
19

UNCOV
20
        return $jobModel->getBaseJob();
×
21
    }
22

23
    /**
24
     * @param int $promise_id
25
     *
26
     * @return Collection<array-key, BaseJob>
27
     */
28
    public function loadByPromiseId(int $promise_id): Collection
29
    {
UNCOV
30
        return PromiseJob::byPromise($promise_id)
×
UNCOV
31
            ->get()
×
UNCOV
32
            ->map(
×
UNCOV
33
                function (PromiseJob $jobModel): BaseJob {
×
UNCOV
34
                    return $jobModel->getBaseJob();
×
UNCOV
35
                },
×
UNCOV
36
            );
×
37
    }
38

39
    /**
40
     * @param int $promise_id
41
     *
42
     * @return LazyCollection<int, BaseJob>
43
     */
44
    public function loadByPromiseIdCursor(int $promise_id): LazyCollection
45
    {
UNCOV
46
        return LazyCollection::make(
×
UNCOV
47
            function () use ($promise_id) {
×
48
                /** @var PromiseJob $job */
UNCOV
49
                foreach (PromiseJob::byPromise($promise_id)->cursor() as $job) {
×
UNCOV
50
                    yield $job->getBaseJob();
×
51
                }
UNCOV
52
            },
×
UNCOV
53
        );
×
54
    }
55

56
    public function loadByPromiseIdChunk(int $promise_id, callable $callback, int $chunk_size = 1000): void
57
    {
UNCOV
58
        PromiseJob::byPromise($promise_id)->chunk(
×
UNCOV
59
            $chunk_size,
×
UNCOV
60
            function (Collection $jobs) use ($callback) {
×
61
                /** @var Collection<int, PromiseJob> $jobs */
UNCOV
62
                foreach ($jobs as $job) {
×
UNCOV
63
                    $callback($job->getBaseJob());
×
64
                }
UNCOV
65
            },
×
UNCOV
66
        );
×
67
    }
68

69
    public function countByPromiseId(int $promise_id): int
70
    {
UNCOV
71
        return PromiseJob::byPromise($promise_id)->count();
×
72
    }
73

74
    public function save(BaseJob $job): void
75
    {
UNCOV
76
        PromiseJob::saveBaseJob($job);
×
77
    }
78

79
    public function deleteByPromiseId(int $promise_id): void
80
    {
UNCOV
81
        PromiseJob::byPromise($promise_id)->delete();
×
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc