|
|
@@ -17,20 +17,18 @@ class CustomerTest extends TestCase
|
|
|
{
|
|
|
parent::setUp();
|
|
|
$this->service = app(CustomerService::class);
|
|
|
- $this->data = factory(Customer::class,3)->create()->toArray();
|
|
|
+ $this->data = [
|
|
|
+ "models"=>factory(Customer::class,3)->create()->toArray()
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
- public function create(){
|
|
|
+ public function testCreate(){
|
|
|
$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;
|
|
|
- $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(){
|
|
|
$models = $this->service->getSelection(["id","name","company_name"]);
|
|
|
@@ -43,30 +41,28 @@ class CustomerTest extends TestCase
|
|
|
$this->assertLessThanOrEqual(5,count($models));
|
|
|
}
|
|
|
public function testFind(){
|
|
|
- $model = $this->service->find($this->data["model"]["id"]);
|
|
|
+ $model = $this->service->find($this->data["models"][0]["id"]);
|
|
|
$this->assertNotNull($model);
|
|
|
}
|
|
|
public function testUpdate()
|
|
|
{
|
|
|
$value = date('YmdH').Str::random(4);
|
|
|
- $row = $this->service->update(["id"=>$this->data[0]["id"]],[
|
|
|
+ $row = $this->service->update(["id"=>$this->data["models"][0]["id"]],[
|
|
|
"name" => $value,
|
|
|
]);
|
|
|
- $this->data["model"]["name"] = $value;
|
|
|
+ $this->data["models"][0]["name"] = $value;
|
|
|
$this->assertEquals($row,1);
|
|
|
}
|
|
|
public function testDestroy()
|
|
|
{
|
|
|
- $row = $this->service->destroy($this->data[0]["id"]);
|
|
|
+ $row = $this->service->destroy($this->data["models"][0]["id"]);
|
|
|
$this->assertEquals($row,1);
|
|
|
- $this->assertDeleted("customers", $this->data["model"]);
|
|
|
+ $this->assertDeleted("customers", $this->data["models"][0]);
|
|
|
}
|
|
|
|
|
|
public function tearDown(): void
|
|
|
{
|
|
|
+ Customer::destroy(array_column($this->data["models"],'id'));
|
|
|
parent::tearDown();
|
|
|
- $ids = array_column($this->data,'id');
|
|
|
- $row = Customer::destroy($ids);
|
|
|
- $this->assertGreaterThan(0,$row);
|
|
|
}
|
|
|
}
|