public function testInsert() { list($conn, $query) = $this->getMocks(); $instance = new CategoryRepository($conn); $mockEntity = m::mock('Xpressengine\\Category\\CategoryEntity'); $mockEntity->shouldReceive('getAttributes')->andReturn(['name' => 'cate']); $conn->shouldReceive('table')->andReturn($query); $query->shouldReceive('insertGetId')->once()->with(m::on(function ($array) { return $array['name'] === 'cate'; }))->andReturn(1); $category = $instance->insert($mockEntity); $this->assertInstanceOf('Xpressengine\\Category\\CategoryEntity', $category); $this->assertEquals(1, $category->id); $this->assertEquals('cate', $category->name); }
/** * Category add to repository * * @param CategoryEntity $category category object * @return CategoryEntity */ public function add(CategoryEntity $category) { return $this->repo->insert($category); }