Skip to content

Commit aa2e652

Browse files
committed
prepare tests, added justNow scope and fixed second scopes
1 parent b435390 commit aa2e652

File tree

5 files changed

+131
-21
lines changed

5 files changed

+131
-21
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace LaracraftTech\LaravelDateScopes\Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use LaracraftTech\LaravelDateScopes\Tests\Models\Transaction;
7+
8+
class TransactionFactory extends Factory
9+
{
10+
protected $model = Transaction::class;
11+
12+
public function definition(): array
13+
{
14+
return [
15+
'col1' => fake()->sentence(),
16+
'col2' => fake()->randomNumber(),
17+
'created_at' => fake()->date(),
18+
];
19+
}
20+
}

ray.php

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
return [
4+
/*
5+
* This setting controls whether data should be sent to Ray.
6+
*
7+
* By default, `ray()` will only transmit data in non-production environments.
8+
*/
9+
'enable' => env('RAY_ENABLED', true),
10+
11+
/*
12+
* When enabled, all cache events will automatically be sent to Ray.
13+
*/
14+
'send_cache_to_ray' => env('SEND_CACHE_TO_RAY', false),
15+
16+
/*
17+
* When enabled, all things passed to `dump` or `dd`
18+
* will be sent to Ray as well.
19+
*/
20+
'send_dumps_to_ray' => env('SEND_DUMPS_TO_RAY', true),
21+
22+
/*
23+
* When enabled all job events will automatically be sent to Ray.
24+
*/
25+
'send_jobs_to_ray' => env('SEND_JOBS_TO_RAY', false),
26+
27+
/*
28+
* When enabled, all things logged to the application log
29+
* will be sent to Ray as well.
30+
*/
31+
'send_log_calls_to_ray' => env('SEND_LOG_CALLS_TO_RAY', false),
32+
33+
/*
34+
* When enabled, all queries will automatically be sent to Ray.
35+
*/
36+
'send_queries_to_ray' => env('SEND_QUERIES_TO_RAY', false),
37+
38+
/**
39+
* When enabled, all duplicate queries will automatically be sent to Ray.
40+
*/
41+
'send_duplicate_queries_to_ray' => env('SEND_DUPLICATE_QUERIES_TO_RAY', false),
42+
43+
/*
44+
* When enabled, slow queries will automatically be sent to Ray.
45+
*/
46+
'send_slow_queries_to_ray' => env('SEND_SLOW_QUERIES_TO_RAY', false),
47+
48+
/*
49+
* When enabled, all requests made to this app will automatically be sent to Ray.
50+
*/
51+
'send_requests_to_ray' => env('SEND_REQUESTS_TO_RAY', false),
52+
53+
/**
54+
* When enabled, all Http Client requests made by this app will be automatically sent to Ray.
55+
*/
56+
'send_http_client_requests_to_ray' => env('SEND_HTTP_CLIENT_REQUESTS_TO_RAY', false),
57+
58+
/*
59+
* When enabled, all views that are rendered automatically be sent to Ray.
60+
*/
61+
'send_views_to_ray' => env('SEND_VIEWS_TO_RAY', false),
62+
63+
/*
64+
* When enabled, all exceptions will be automatically sent to Ray.
65+
*/
66+
'send_exceptions_to_ray' => env('SEND_EXCEPTIONS_TO_RAY', true),
67+
68+
/*
69+
* The host used to communicate with the Ray app.
70+
* When using Docker on Mac or Windows, you can replace localhost with 'host.docker.internal'
71+
* When using Homestead with the VirtualBox provider, you can replace localhost with '10.0.2.2'
72+
* When using Homestead with the Parallels provider, you can replace localhost with '10.211.55.2'
73+
*/
74+
'host' => env('RAY_HOST', 'host.docker.internal'),
75+
76+
/*
77+
* The port number used to communicate with the Ray app.
78+
*/
79+
'port' => env('RAY_PORT', 23517),
80+
81+
/*
82+
* Absolute base path for your sites or projects in Homestead,
83+
* Vagrant, Docker, or another remote development server.
84+
*/
85+
'remote_path' => env('RAY_REMOTE_PATH', null),
86+
87+
/*
88+
* Absolute base path for your sites or projects on your local
89+
* computer where your IDE or code editor is running on.
90+
*/
91+
'local_path' => env('RAY_LOCAL_PATH', null),
92+
93+
/*
94+
* When this setting is enabled, the package will not try to format values sent to Ray.
95+
*/
96+
'always_send_raw_values' => false,
97+
];

src/DateScopes.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public function scopeOfLastUnit(Builder $query, string $dateUnit, int $value, Da
4141

4242
$applyNoOverflow = (! in_array($dateUnit, $this->fixedLengthDateUnits)) ? 'NoOverflow' : '' ;
4343
$subFunc = 'sub'.ucfirst($dateUnit).'s'.$applyNoOverflow;
44-
45-
$sub = ($dateUnit === 'second') ? 0 : 1;
46-
// $sub = 1;
44+
$sub = 1;
4745

4846
if ($dateRange === DateRange::EXCLUSIVE) {
4947
$range = [
@@ -57,7 +55,7 @@ public function scopeOfLastUnit(Builder $query, string $dateUnit, int $value, Da
5755
];
5856
}
5957

60-
// dump(collect($range)->transform(fn ($item) => $item->format('Y-m-d H:i:s'))->toArray());
58+
//dump(collect($range)->transform(fn ($item) => $item->format('Y-m-d H:i:s'))->toArray());
6159

6260
return $query->whereBetween(config('date-scopes.created_column'), $range);
6361
}

tests/DataScopesTest.php

-17
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,8 @@ function getCreatedAtValues(): array
9898
->count(count($createdAtValues))
9999
->state(new Sequence(...$createdAtValues))
100100
->create();
101-
102-
Transaction::ofJustNow()->get();
103-
Transaction::ofLast15Seconds(DateRange::INCLUSIVE)->get();
104-
Transaction::ofLast15Seconds(DateRange::EXCLUSIVE)->get();
105-
dd();
106101
});
107102

108-
it('retrieves transactions of last x seconds', function () {
109-
// expect(Transaction::ofJustNow()->get())->toHaveCount(1);
110-
// expect(Transaction::ofLastSecond()->get())->toHaveCount(1);
111-
// expect(Transaction::ofLast15Seconds(DateRange::INCLUSIVE)->get())->toHaveCount(2);
112-
// expect(Transaction::ofLast15Seconds(DateRange::EXCLUSIVE)->get())->toHaveCount(2);
113-
114-
115-
// Transaction::ofToday()->get();
116-
// Transaction::ofYesterday()->get();
117-
// Transaction::ofLast7Days()->get();
118-
});
119-
//
120103
it('covers all cases', function () {
121104
//TODO
122105
// Write tests for all kind of scopes

tests/Models/Transaction.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace LaracraftTech\LaravelDateScopes\Tests\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use LaracraftTech\LaravelDateScopes\DateScopes;
8+
9+
class Transaction extends Model
10+
{
11+
use HasFactory, DateScopes;
12+
}

0 commit comments

Comments
 (0)