|
|
@@ -17,45 +17,39 @@ class CustomerTest extends TestCase
|
|
|
{
|
|
|
parent::setUp();
|
|
|
$this->service = app(CustomerService::class);
|
|
|
- $this->data = [
|
|
|
- "model" => [
|
|
|
- "code" => date('Ymd').Str::random(4),
|
|
|
- "name" => date('Ymd').Str::random(5),
|
|
|
- "company_name" => date('Ymd').Str::random(6),
|
|
|
- ]
|
|
|
- ];
|
|
|
+ $this->data = factory(Customer::class,3)->create()->toArray();
|
|
|
}
|
|
|
|
|
|
public function create(){
|
|
|
- $model = $this->service->create($this->data["model"]);
|
|
|
+ $model = $this->service->create([
|
|
|
+ "code" => date('Ymd').Str::random(4),
|
|
|
+ "name" => date('Ymd').Str::random(5),
|
|
|
+ "company_name" => date('Ymd').Str::random(6),
|
|
|
+ ]);
|
|
|
$this->assertNotNull($model);
|
|
|
- $this->data["model"]["id"] = $model->id;
|
|
|
+ $this->data[] = $model;
|
|
|
$this->assertEquals($model->code,$this->data["model"]["code"]);
|
|
|
$this->assertEquals($model->name,$this->data["model"]["name"]);
|
|
|
$this->assertEquals($model->company_name,$this->data["model"]["company_name"]);
|
|
|
}
|
|
|
public function testGetSelection(){
|
|
|
- $this->create();
|
|
|
$models = $this->service->getSelection(["id","name","company_name"]);
|
|
|
$this->assertGreaterThanOrEqual(1,count($models));
|
|
|
$this->assertArrayHasKey("company_name",$models[0]);
|
|
|
}
|
|
|
public function testPaginate(){
|
|
|
- $this->create();
|
|
|
$models = $this->service->paginate(5);
|
|
|
$this->assertGreaterThanOrEqual(1,count($models));
|
|
|
$this->assertLessThanOrEqual(5,count($models));
|
|
|
}
|
|
|
public function testFind(){
|
|
|
- $this->create();
|
|
|
$model = $this->service->find($this->data["model"]["id"]);
|
|
|
$this->assertNotNull($model);
|
|
|
}
|
|
|
public function testUpdate()
|
|
|
{
|
|
|
- $this->create();
|
|
|
$value = date('YmdH').Str::random(4);
|
|
|
- $row = $this->service->update(["id"=>$this->data["model"]["id"]],[
|
|
|
+ $row = $this->service->update(["id"=>$this->data[0]["id"]],[
|
|
|
"name" => $value,
|
|
|
]);
|
|
|
$this->data["model"]["name"] = $value;
|
|
|
@@ -63,16 +57,16 @@ class CustomerTest extends TestCase
|
|
|
}
|
|
|
public function testDestroy()
|
|
|
{
|
|
|
- $this->create();
|
|
|
- $row = $this->service->destroy($this->data["model"]["id"]);
|
|
|
+ $row = $this->service->destroy($this->data[0]["id"]);
|
|
|
$this->assertEquals($row,1);
|
|
|
$this->assertDeleted("customers", $this->data["model"]);
|
|
|
}
|
|
|
|
|
|
- public function testTruncate()
|
|
|
+ public function tearDown(): void
|
|
|
{
|
|
|
- Customer::query()->truncate();
|
|
|
- $customers = Customer::query()->get();
|
|
|
- $this->assertCount(0,$customers);
|
|
|
+ parent::tearDown();
|
|
|
+ $ids = array_column($this->data,'id');
|
|
|
+ $row = Customer::destroy($ids);
|
|
|
+ $this->assertGreaterThan(0,$row);
|
|
|
}
|
|
|
}
|