delete(); // Clear existing $segment = new Segment(); $segment->name = 'test_it_can_list_segment_constants_SEG'; $segment->save(); $c1 = new SegmentConstant(); $c1->segment_id = $segment->id; $c1->name = 'test_it_can_list_segment_constants_A'; $c1->reference = 'test_it_can_list_segment_constants_REF_A'; $c1->detail = (object) ['foo' => 'bar']; $c1->save(); $c2 = new SegmentConstant(); $c2->segment_id = $segment->id; $c2->name = 'test_it_can_list_segment_constants_B'; $c2->reference = 'test_it_can_list_segment_constants_REF_B'; $c2->detail = (object) ['foo' => 'bar']; $c2->save(); $service = new ListsConstants(new SegmentConstant()); // A C T $result = $service->execute(); // A S S E R T $this->assertInstanceOf(Collection::class, $result); $this->assertCount(2, $result); $this->assertTrue($result->contains('name', 'test_it_can_list_segment_constants_A')); $this->assertTrue($result->contains('name', 'test_it_can_list_segment_constants_B')); } /** * Test it can list segment constants with filters. * * @return void */ public function test_it_can_filter_segment_constants_by_segment_id() { // A R R A N G E SegmentConstant::query()->delete(); $segment1 = new Segment(); $segment1->name = 'test_it_can_filter_segment_constants_by_segment_id_SEG1'; $segment1->save(); $segment2 = new Segment(); $segment2->name = 'test_it_can_filter_segment_constants_by_segment_id_SEG2'; $segment2->save(); $c1 = new SegmentConstant(); $c1->segment_id = $segment1->id; $c1->name = 'test_it_can_filter_segment_constants_by_segment_id_C1'; $c1->reference = 'test_it_can_filter_segment_constants_by_segment_id_REF1'; $c1->detail = (object) ['foo' => 'bar']; $c1->save(); $c2 = new SegmentConstant(); $c2->segment_id = $segment2->id; $c2->name = 'test_it_can_filter_segment_constants_by_segment_id_C2'; $c2->reference = 'test_it_can_filter_segment_constants_by_segment_id_REF2'; $c2->detail = (object) ['foo' => 'bar']; $c2->save(); $service = new ListsConstants(new SegmentConstant()); // A C T $result = $service->execute(['segment_id' => $segment1->id]); // A S S E R T $this->assertCount(1, $result); $this->assertEquals('test_it_can_filter_segment_constants_by_segment_id_REF1', $result->first()->reference); } }