| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace Tests\Services\OwnerService;
- use App\OracleBasCustomer;
- use App\Owner;
- use App\Services\OwnerService;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Foundation\Testing\WithFaker;
- use Tests\TestCase;
- class GetOwnerByCodesTest extends TestCase
- {
- use RefreshDatabase;
- /** @var OwnerService $service */
- private $service;
- private $data;
- public function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $this->service = app('OwnerService');
- $owner1 = factory(Owner::class)->create();
- $owner2 = factory(Owner::class)->create();
- $owner3 = factory(Owner::class)->create();
- $this->data['owner'] = [$owner1,$owner2,$owner3];
- $this->service = app('OwnerService');
- $basCustomer1 = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$owner1->code]);
- $basCustomer2 = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$owner2->code]);
- $basCustomer3 = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$owner3->code]);
- $basCustomers = collect([$basCustomer1,$basCustomer2,$basCustomer3]);
- $this->mock('OracleBasCustomerService',function ($mock)use($basCustomers,$owner1, $owner2, $owner3){
- $mock->shouldReceive('first')->once()->with(["customer_type"=>'OW',"customerid"=>$owner1->code])->andReturn($basCustomers->where('customerid',$owner1->code)->first());
- $mock->shouldReceive('first')->once()->with(["customer_type"=>'OW',"customerid"=>$owner2->code])->andReturn($basCustomers->where('customerid',$owner2->code)->first());
- $mock->shouldReceive('first')->once()->with(["customer_type"=>'WO',"customerid"=>$owner3->code])->andReturn($basCustomers->where('customerid',$owner3->code)->first());
- });
- }
- /**
- * @test
- */
- public function getOwnerByCodesNormal()
- {
- $owners = $this->service->getOwnerByCodes(data_get($this->data['owner'],'*.code'));
- $this->assertNotNull($owners);
- $this->assertNotEquals(count($owners),0);
- $this->assertNotEquals(count($owners),1);
- $this->assertEquals(count($owners),count($this->data['owner']['code']));
- foreach ($this->data['owner'] as $item) {
- $owner = $owners->where('code',$item['code'])->first();
- $this->assertEquals($owner->id,$item['id']);
- $this->assertEquals($owner->name,$item['name']);
- $this->assertEquals($owner->code,$item['code']);
- }
- }
- /**
- * @test
- */
- public function ownerIsNotExist()
- {
- foreach ($this->data['owner'] as $owner)
- $owner->delete();
- $owners = $this->service->getOwnerByCodes(data_get($this->data['owner'],'*.code'));
- $this->assertNotNull($owners);
- $this->assertNotEquals(count($owners),0);
- $this->assertNotEquals(count($owners),1);
- $this->assertEquals(count($owners),count($this->data['owner']['code']));
- foreach ($this->data['owner'] as $item) {
- $owner = $owners->where('code',$item['code'])->first();
- $this->assertEquals($owner->id,$item['id']);
- $this->assertEquals($owner->name,$item['name']);
- $this->assertEquals($owner->code,$item['code']);
- }
- }
- public function tearDown(): void
- {
- cache()->flush();
- foreach ($this->data['owner'] as $owner) {
- $owner->delete();
- }
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- }
|