public function testFetchCommit() { $commitHash = 'commit-hash'; $treeHash = 'tree-hash'; $message = 'My message'; $username = '******'; $createdAt = new \DateTime(); $factory = $this->getFactory(); $tree = $this->prophesize(TreeInterface::class); $tree->getHash()->willReturn($treeHash); $user = $this->prophesize(UserInterface::class); $user->getUsername()->willReturn($username); $commit = new Commit(); $commit->setPolicyCollection(new PolicyCollection()); $commit->setHash($commitHash); $commit->setTree($tree->reveal()); $commit->setCommitter($user->reveal()); $commit->setCreatedAt(new \DateTime()); $commit->setMessage($message); $commit->setParentCommit(null); $database = $this->prophesize(DatabaseInterface::class); $database->fetch($commitHash, Commit::class)->willReturn($commit); $userProvider = $this->prophesize(UserProviderInterface::class); $userProvider->loadUserByUsername($username)->willReturn($user); $commitManager = new CommitManager($factory, $database->reveal(), $userProvider->reveal()); $result = $commitManager->fetch($commitHash); $this->assertEquals($commitHash, $result->getHash()); $this->assertEquals($treeHash, $result->getTree()->getHash()); $this->assertEquals($createdAt->format(\DateTime::ISO8601), $result->getCreatedAt()->format(\DateTime::ISO8601)); $this->assertEquals($message, $result->getMessage()); $this->assertEquals($username, $result->getCommitter()->getUsername()); $this->assertEquals(null, $result->getParentCommit()); }
public function testFetchCommit() { $commitManager = $this->getCommitManager(); $database = $this->getDatabase(); $username = '******'; $message = 'My message'; $user = $this->getUserProvider()->loadUserByUsername($username); $tree = new Tree(); $tree->setPolicyCollection(new PolicyCollection()); $tree->setName(''); $tree->setPath('/'); $database->store($tree); $commit = new Commit(); $commit->setPolicyCollection(new PolicyCollection()); $commit->setMessage($message); $commit->setCommitter($user); $commit->setCreatedAt(new \DateTime()); $commit->setTree($tree); $commit->setParentCommit(null); $database->store($commit); $commitManager->fetch($commit->getHash()); $this->assertEquals($tree->getHash(), $commit->getTree()->getHash()); $this->assertEquals($user->getUsername(), $commit->getCommitter()->getUsername()); $this->assertEquals($message, $commit->getMessage()); $this->assertInstanceOf(\DateTime::class, $commit->getCreatedAt()); $this->assertEquals(null, $commit->getParentCommit()); }
public function dataProvider() { $username = '******'; $message = 'My message'; $user = $this->getUserProvider()->loadUserByUsername($username); $tree = new Tree(); $tree->setPolicyCollection(new PolicyCollection()); $tree->setName(''); $tree->setPath('/'); $commit = new Commit(); $commit->setPolicyCollection(new PolicyCollection()); $commit->setMessage('init'); $commit->setCommitter($user); $commit->setCreatedAt(new \DateTime()); $commit->setTree($tree); $commit->setParentCommit(null); $commit2 = new Commit(); $commit2->setPolicyCollection(new PolicyCollection()); $commit2->setMessage($message); $commit2->setCommitter($user); $commit2->setCreatedAt(new \DateTime()); $commit2->setTree($tree); $commit2->setParentCommit($commit); return array(array('my-hash', $commit, $commit2, $tree, $user)); }
/** * {@inheritdoc} */ public function commit(TreeInterface $tree, UserInterface $user, $message = '', CommitInterface $parentCommit = null) { $commit = new Commit(); $commit->setPolicyCollection(new PolicyCollection()); $commit->setCommitter($user); $commit->setParentCommit($parentCommit); $commit->setCreatedAt(new \DateTime()); $commit->setMessage($message); $commit->setTree($tree); return $this->database->store($commit); }