• 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

92.0
/src/Models/PromiseEvent.php
1
<?php
2

3
/** @noinspection PhpMissingFieldTypeInspection */
4

5
namespace Tochka\Promises\Models;
6

7
use Carbon\Carbon;
8
use Illuminate\Database\Eloquent\Builder;
9
use Illuminate\Database\Eloquent\Factories\HasFactory;
10
use Illuminate\Database\Eloquent\Model;
11
use Illuminate\Database\Eloquent\Relations\BelongsTo;
12
use Illuminate\Support\Facades\Config;
13
use Tochka\Promises\Exceptions\UnknownBaseJobIdException;
14
use Tochka\Promises\Models\Casts\SerializableClassCast;
15
use Tochka\Promises\Models\Factories\PromiseEventFactory;
16
use Tochka\Promises\Support\WaitEvent;
17

18
/**
19
 * @api
20
 * @property int $id
21
 * @property int $job_id
22
 * @property string $event_name
23
 * @property string $event_unique_id
24
 * @property Carbon $created_at
25
 * @property Carbon $updated_at
26
 * @property PromiseJob|null $job
27
 *
28
 * @psalm-suppress PropertyNotSetInConstructor
29
 */
30
class PromiseEvent extends Model
31
{
32
    use HasFactory;
33

34
    protected $casts = [
35
        'job_id' => 'int',
36
        'event_name' => 'string',
37
        'event_unique_id' => 'string',
38
        'event' => SerializableClassCast::class,
39
    ];
40

41
    private ?WaitEvent $baseEvent = null;
42

43
    public function getConnectionName(): ?string
44
    {
45
        /** @noinspection PhpRedundantOptionalArgumentInspection */
46
        return Config::get('promises.database.connection', null);
9✔
47
    }
48

49
    public function getTable(): string
50
    {
51
        return Config::get('promises.database.table_events', 'promise_events');
9✔
52
    }
53

54
    /**
55
     * @return BelongsTo
56
     */
57
    public function job(): BelongsTo
58
    {
UNCOV
59
        return $this->belongsTo(PromiseJob::class, 'promise_id', 'id');
×
60
    }
61

62
    public function scopeByJob(Builder $query, int $jobId): Builder
63
    {
64
        return $query->where('job_id', $jobId);
3✔
65
    }
66

67
    public function scopeByEvent(Builder $query, string $eventName, string $eventUniqueId): Builder
68
    {
69
        return $query->where('event_name', $eventName)->where('event_unique_id', $eventUniqueId);
3✔
70
    }
71

72
    public function getWaitEvent(): WaitEvent
73
    {
74
        if ($this->baseEvent === null) {
3✔
75
            $this->baseEvent = new WaitEvent($this->event_name, $this->event_unique_id);
3✔
76
        }
77

78
        $this->baseEvent->setId($this->id);
3✔
79
        $this->baseEvent->setBaseJobId($this->job_id);
3✔
80
        $this->baseEvent->setAttachedModel($this);
3✔
81

82
        return $this->baseEvent;
3✔
83
    }
84

85
    public static function saveWaitEvent(WaitEvent $waitEvent): self
86
    {
87
        $model = $waitEvent->getAttachedModel();
3✔
88
        if ($model === null) {
3✔
89
            $model = new self();
3✔
90
        }
91
        $baseJobId = $waitEvent->getBaseJobId();
3✔
92
        if ($baseJobId === null) {
3✔
UNCOV
93
            throw new UnknownBaseJobIdException();
×
94
        }
95

96
        $model->job_id = $baseJobId;
3✔
97
        $model->event_name = $waitEvent->getEventName();
3✔
98
        $model->event_unique_id = $waitEvent->getEventUniqueId();
3✔
99

100
        $model->save();
3✔
101

102
        $waitEvent->setId($model->id);
3✔
103
        $waitEvent->setAttachedModel($model);
3✔
104

105
        return $model;
3✔
106
    }
107

108
    protected static function newFactory(): PromiseEventFactory
109
    {
110
        return new PromiseEventFactory();
6✔
111
    }
112
}
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

© 2025 Coveralls, Inc