Пример #1
0
 /**
  * @test
  */
 public function format()
 {
     $id = 42;
     $title = "foobarbaz";
     $createdAtUnixTime = 1234567890;
     $lastPostedAtUnixTime = 1333333333;
     $tags = ["foo", "bar"];
     $tag1 = new Tag();
     $tag1->setName($tags[0]);
     $tag2 = new Tag();
     $tag2->setName($tags[1]);
     $thread = $this->getMock('Kumatch\\BBSAPI\\Entity\\Thread', array("getId"));
     $thread->expects($this->any())->method("getId")->will($this->returnValue($id));
     /** @var Thread $thread */
     $thread->setTitle($title)->setCreatedAt(new \DateTime('@' . $createdAtUnixTime))->addTag($tag1)->addTag($tag2);
     $results = $this->spec->format($thread);
     $this->assertEquals($id, $results["id"]);
     $this->assertEquals($title, $results["title"]);
     $this->assertEquals($createdAtUnixTime, $results["created_at"]);
     $this->assertEquals($tags, $results["tags"]);
     $this->assertFalse(isset($results["last_posted_at"]));
     $thread->setLastPostedAt(new \DateTime('@' . $lastPostedAtUnixTime));
     $results2 = $this->spec->format($thread);
     $this->assertEquals($lastPostedAtUnixTime, $results2["last_posted_at"]);
 }
 /**
  * @param Tag $tag
  * @return Tag
  */
 public function register(Tag $tag)
 {
     $existsTag = $this->findByName($tag->getName());
     if ($existsTag) {
         return $existsTag;
     }
     $this->tagRepository->add($tag);
     $this->entityManager->flush();
     return $tag;
 }
Пример #3
0
 /**
  * @test
  * @dataProvider provideInvalidTagName
  * @param string $name
  * @param int $errorSize
  */
 public function invalidTagName($name, $errorSize = 1)
 {
     $tag = new Tag();
     $tag->setName($name);
     $result = $this->spec->validate($tag);
     $errors = $result->getErrors();
     $this->assertFalse($result->isValid());
     $this->assertCount(1, $errors);
     $this->assertCount($errorSize, $errors["name"]);
 }
Пример #4
0
 /**
  * @param string[]|null $tagNames
  */
 public function __construct(array $tagNames = null)
 {
     if (is_null($tagNames)) {
         parent::__construct();
         return;
     }
     $tags = [];
     foreach ($tagNames as $tagName) {
         if (is_string($tagName) && $tagName !== "") {
             $tag = new Tag();
             $tag->setName(trim($tagName));
             array_push($tags, $tag);
         }
     }
     parent::__construct($tags);
 }
 /**
  * @test
  */
 public function getAExistsTagAndDoNotRegistration()
 {
     $name = "foo";
     $tag = new Tag();
     $tag->setName($name);
     $tagRepo = $this->getMock("RepositoryMock", array("findOneBy", "add"));
     $tagRepo->expects($this->once())->method("findOneBy")->with($this->equalTo(array("name" => $name)))->will($this->returnValue($tag));
     $tagRepo->expects($this->never())->method("add");
     $em = $this->getEntityManagerMock(array("getRepository", "flush"));
     $em->expects($this->once())->method("getRepository")->with($this->equalTo(EntityConstant::TAG))->will($this->returnValue($tagRepo));
     $em->expects($this->never())->method("flush");
     /** @var EntityManager $em */
     $useCase = new TagRegistration($em);
     $tag = $useCase->register($tag);
     $this->assertInstanceOf('Kumatch\\BBSAPI\\Entity\\Tag', $tag);
     $this->assertEquals($name, $tag->getName());
 }