delete(); // Clear existing $segment1 = new Segment(); $segment1->name = 'test_it_can_list_segments_1'; $segment1->save(); $segment2 = new Segment(); $segment2->name = 'test_it_can_list_segments_2'; $segment2->save(); $service = new ListsSegments(new Segment()); // 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_segments_1')); $this->assertTrue($result->contains('name', 'test_it_can_list_segments_2')); } /** * Test it can list segments with pagination. * * @return void */ public function test_it_can_paginate_segments() { // A R R A N G E Segment::query()->delete(); for ($i = 1; $i <= 5; $i++) { $s = new Segment(); $s->name = "test_it_can_paginate_segments_$i"; $s->save(); } $service = new ListsSegments(new Segment()); // A C T $result = $service->execute(['per_page' => 2]); // A S S E R T $this->assertInstanceOf(LengthAwarePaginator::class, $result); $this->assertEquals(2, $result->perPage()); $this->assertEquals(5, $result->total()); } }