parent
abdebd3c9a
commit
35761327f9
@ -1,8 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
namespace App\Interfaces; |
|
||||||
|
|
||||||
interface ConverterInterface |
|
||||||
{ |
|
||||||
public function handle(): void; |
|
||||||
} |
|
||||||
@ -0,0 +1,24 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Pipes\StoreChunk; |
||||||
|
|
||||||
|
use Illuminate\Support\Carbon; |
||||||
|
use Illuminate\Support\Collection; |
||||||
|
|
||||||
|
class AgeFilterPipe |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @param Collection $chunk |
||||||
|
* @param \Closure $next |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function handle($chunk, \Closure $next) |
||||||
|
{ |
||||||
|
$chunk = $chunk->filter(function ($item) { |
||||||
|
$age = $item['date_of_birth']->age; |
||||||
|
return 18 <= $age && $age <= 65; |
||||||
|
}); |
||||||
|
|
||||||
|
return $next($chunk); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Pipes\StoreChunk; |
||||||
|
|
||||||
|
use Illuminate\Support\Collection; |
||||||
|
|
||||||
|
class CreditCardFilter |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @param Collection $chunk |
||||||
|
* @param \Closure $next |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function handle($chunk, \Closure $next) |
||||||
|
{ |
||||||
|
// filter based on credit card number |
||||||
|
|
||||||
|
return $next($chunk); |
||||||
|
} |
||||||
|
} |
||||||
@ -1,10 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
namespace App\Services\Converters; |
|
||||||
|
|
||||||
use App\Interfaces\ConverterInterface; |
|
||||||
|
|
||||||
class JsonToDatabaseConverter implements ConverterInterface |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,3 @@ |
|||||||
|
create database testing; |
||||||
|
GRANT ALL ON `testing`.* TO 'sail'@'%'; |
||||||
|
FLUSH PRIVILEGES; |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Tests\Unit\Jobs; |
||||||
|
|
||||||
|
use App\Jobs\StoreChunk; |
||||||
|
use App\Models\User; |
||||||
|
use Illuminate\Database\Eloquent\Factories\Sequence; |
||||||
|
use Tests\TestCase; |
||||||
|
|
||||||
|
class StoreChunkTest extends TestCase |
||||||
|
{ |
||||||
|
/** |
||||||
|
* A basic unit test example. |
||||||
|
* |
||||||
|
* @return void |
||||||
|
* @group convert2 |
||||||
|
*/ |
||||||
|
public function test_store_chunk() |
||||||
|
{ |
||||||
|
(new StoreChunk( |
||||||
|
User::factory()->count(99)->state( |
||||||
|
new Sequence( |
||||||
|
[ |
||||||
|
'date_of_birth' => fake()->dateTimeBetween('-70 years', '-66 years'), |
||||||
|
], |
||||||
|
[ |
||||||
|
'date_of_birth' => fake()->dateTimeBetween('-65 years', '-18 years'), |
||||||
|
], |
||||||
|
[ |
||||||
|
'date_of_birth' => fake()->dateTimeBetween('-18 years', 'now'), |
||||||
|
] |
||||||
|
) |
||||||
|
)->make()->toArray() |
||||||
|
))->handle(); |
||||||
|
|
||||||
|
$this->assertDatabaseCount('users', 33); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue