public function setUp() { parent::setUp(); $this->removeClass(); $this->Member = $this->app['eccube.repository.member']->find(2); for ($i = 0; $i < 3; $i++) { $ClassName = new ClassName(); $ClassName->setName('class-' . $i)->setCreator($this->Member)->setDelFlg(0)->setRank($i); $this->app['orm.em']->persist($ClassName); } $this->app['orm.em']->flush(); }
public function testSaveWithRankNull() { $this->removeClass(); // 一旦全件削除 $ClassName = new ClassName(); $ClassName->setName('class-3')->setCreator($this->Member); $result = $this->app['eccube.repository.class_name']->save($ClassName); $this->assertTrue($result); $faker = $this->getFaker(); $ClassCategory = new ClassCategory(); $ClassCategory->setName($faker->name)->setClassName($ClassName)->setCreator($this->Member); $result = $this->app['eccube.repository.class_category']->save($ClassCategory); $this->assertTrue($result, '保存に成功したかどうか'); $this->expected = 1; $this->actual = $ClassCategory->getRank(); $this->verify('rank は' . $this->expected . 'ではありません'); }
private function newTestClassName($TestCreator) { $TestClassName = new \Eccube\Entity\ClassName(); $TestClassName->setName('形状')->setRank(100)->setDelFlg(false)->setCreator($TestCreator); return $TestClassName; }
/** * @param \Eccube\Entity\ClassName $ClassName * @return bool */ public function delete(\Eccube\Entity\ClassName $ClassName) { $em = $this->getEntityManager(); $em->getConnection()->beginTransaction(); try { if ($ClassName->getClassCategories()->count() > 0) { throw new \Exception(); } $rank = $ClassName->getRank(); $em->createQueryBuilder()->update('Eccube\\Entity\\ClassName', 'cn')->set('cn.rank', 'cn.rank - 1')->where('cn.rank > :rank')->setParameter('rank', $rank)->getQuery()->execute(); $ClassName->setDelFlg(1); $em->persist($ClassName); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { $em->getConnection()->rollback(); return false; } return true; }