Skip to content
This repository has been archived by the owner on Sep 23, 2022. It is now read-only.

Commit

Permalink
Fixing test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
wysow committed Oct 24, 2014
1 parent 27d2988 commit 303e1ff
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 57 deletions.
9 changes: 3 additions & 6 deletions src/Knp/Bundle/KnpBundlesBundle/Github/Repo.php
Expand Up @@ -417,16 +417,14 @@ public function validate(Bundle $bundle)
foreach ($tree['tree'] as $id => $fileData) {
if ($fileData['path'] === 'app') {
// this is a Symfony2 app, avoid it
$valid = false;
break;
} else if (false !== strpos($fileData['path'], 'Bundle.php')) {
try {
$file = $contentApi->show($bundle->getOwnerName(), $bundle->getName(), $fileData['path']);
if ('base64' == $file['encoding']) {
if (false === strpos(base64_decode($file['content']), 'Symfony\\Component\\HttpKernel\\Bundle\\Bundle')) {
$valid = false;
if (false !== strpos(base64_decode($file['content']), 'Symfony\\Component\\HttpKernel\\Bundle\\Bundle')) {
$valid = true;
}

$valid = true;
}
} catch(RuntimeException $e) {
$valid = false;
Expand All @@ -440,7 +438,6 @@ public function validate(Bundle $bundle)
$valid = false;
}


return $valid;
}

Expand Down
105 changes: 55 additions & 50 deletions src/Knp/Bundle/KnpBundlesBundle/Tests/Github/RepoTest.php
Expand Up @@ -39,7 +39,7 @@ public function testUpdateComposerSuccess()
/**
* @test
*/
public function isValidSymfonyBundleShouldReturnTRUEIfRepoHasCorrectBundleClass()
public function isValidSymfonyBundleShouldReturnTRUEIfRepoHasCorrectComposerFile()
{
$bundle = new Bundle('KnpLabs/KnpMenuBundle');
$repo = $this->getRepoWithMockedGithubClient('KnpMenuBundle.php', __DIR__ . '/fixtures/info.valid-bundle-class.json');
Expand All @@ -50,18 +50,18 @@ public function isValidSymfonyBundleShouldReturnTRUEIfRepoHasCorrectBundleClass(
/**
* @test
*/
public function isValidSymfonyBundleShouldReturnFALSEIfRepoDoesNotHaveBundleClass()
public function isValidSymfonyBundleShouldReturnTrueIfRepoDoesHaveIncorrectComposerFileButCorrectBundleClass()
{
$bundle = new Bundle('KnpLabs/KnpMenuBundle');
$repo = $this->getRepoWithMockedGithubClient('Smth.php', __DIR__ . '/fixtures/info.valid-bundle-class.json');
$repo = $this->getRepoWithMockedGithubClient('KnpMenuBundle.php', __DIR__ . '/fixtures/info.valid-bundle-class.json', false);

$this->assertFalse($repo->validate($bundle));
$this->assertTrue($repo->validate($bundle));
}

/**
* @test
*/
public function isValidSymfonyBundleShouldReturnFALSEIfRepoHasIncorrectBundleClass()
public function isValidSymfonyBundleShouldReturnFALSEIfRepoHasIncorrectComposerFileAndIncorrectBundleClass()
{
$bundle = new Bundle('KnpLabs/KnpMenuBundle');
$repo = $this->getRepoWithMockedGithubClient('KnpMenuBundle.php', __DIR__ . '/fixtures/info.invalid-bundle-class.json', false);
Expand Down Expand Up @@ -192,82 +192,87 @@ protected function getRepo($httpClient = null)
return new Repo($github, $output, $repoManager, new EventDispatcher(), $this->getOwnerManagerMock());
}

protected function getRepoWithMockedGithubClient($bundleClassName, $bundleClassContentsLink, $valid = true)
protected function getRepoWithMockedGithubClient($bundleClassName, $bundleClassContentsLink, $validComposerFile = true)
{
$json = json_decode(file_get_contents($bundleClassContentsLink), true);

$githubApiContentsMock = $this->getMockBuilder('Github\Api\Repository\Contents')
->disableOriginalConstructor()
->getMock()
;
$githubApiTreesMock = $this->getMockBuilder('Github\Api\GitData\Trees')
$githubApiMock = $this->getMockBuilder('Github\Api\Repo')
->disableOriginalConstructor()
->getMock()
;
$githubApiMock->expects($this->at(0))
->method('contents')
->will($this->returnValue($githubApiContentsMock))
;

$githubApiTreesMock->expects($this->at(0))
if (!$validComposerFile) {
$composerContent = file_get_contents(__DIR__ . '/fixtures/encoded-invalid-composer.json');
} else {
$composerContent = file_get_contents(__DIR__ . '/fixtures/encoded-composer.json');
}

$composer = json_decode($composerContent, true);
$githubApiContentsMock->expects($this->at(0))
->method('show')
->with('KnpLabs', 'KnpMenuBundle', 'master', true)
->will($this->returnValue(array(
"tree" => array(
array(
"path" => $bundleClassName,
)
),
)))
->with('KnpLabs', 'KnpMenuBundle', 'composer.json')
->will($this->returnValue($composer))
;

if ($valid && false !== strpos($bundleClassName, 'KnpMenuBundle')) {
$composer = json_decode(file_get_contents(__DIR__ . '/fixtures/encoded-composer.json'), true);
$githubApiContentsMock->expects($this->at(0))
->method('show')
->with('KnpLabs', 'KnpMenuBundle', 'composer.json')
->will($this->returnValue($composer))
if (!$validComposerFile) {
$githubApiTreesMock = $this->getMockBuilder('Github\Api\GitData\Trees')
->disableOriginalConstructor()
->getMock()
;
} else {
$composer = json_decode(file_get_contents(__DIR__ . '/fixtures/encoded-invalid-composer.json'), true);
$githubApiContentsMock->expects($this->at(0))
$githubApiTreesMock->expects($this->at(0))
->method('show')
->with('KnpLabs', 'KnpMenuBundle', 'composer.json')
->will($this->returnValue($composer))
->with('KnpLabs', 'KnpMenuBundle', 'master', true)
->will($this->returnValue(array(
"tree" => array(
array(
"path" => $bundleClassName,
)
),
)))
;
}

$githubGitMock = $this->getMockBuilder('Github\Api\GitData')
->disableOriginalConstructor()
->getMock()
;

if (!$validComposerFile) {
$githubGitMock->expects($this->at(0))
->method('trees')
->will($this->returnValue($githubApiTreesMock))
;
}

if (!$validComposerFile) {
$githubApiContentsMock->expects($this->at(1))
->method('show')
->with('KnpLabs', 'KnpMenuBundle', $bundleClassName)
->will($this->returnValue($json))
;
}

$githubApiMock = $this->getMockBuilder('Github\Api\Repo')
->disableOriginalConstructor()
->getMock()
;
$githubApiMock->expects($this->at(0))
->method('contents')
->will($this->returnValue($githubApiContentsMock))
;

$githubGitMock = $this->getMockBuilder('Github\Api\GitData')
->disableOriginalConstructor()
->getMock()
;
$githubGitMock->expects($this->at(0))
->method('trees')
->will($this->returnValue($githubApiTreesMock))
;

$githubMock = $this->getMock('Github\Client');
$githubMock->expects($this->at(0))
->method('api')
->with('repo')
->will($this->returnValue($githubApiMock))
;
$githubMock->expects($this->at(1))
->method('api')
->with('git')
->will($this->returnValue($githubGitMock))
;
if (!$validComposerFile) {
$githubMock->expects($this->at(1))
->method('api')
->with('git')
->will($this->returnValue($githubGitMock))
;
}
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');

$repoManager = $this->getMockBuilder('Knp\Bundle\KnpBundlesBundle\Git\RepoManager')
Expand Down
@@ -1 +1 @@
{"encoding": "base64", "content":"ewogICAgIm5hbWUiOiAgICAgICAgICJrbnBsYWJzL2tucC1tZW51LWJ1bmRsZSIsCiAgICAiZGVzY3JpcHRpb24iOiAgIlRoaXMgYnVuZGxlIHByb3ZpZGVzIGFuIGludGVncmF0aW9uIG9mIHRoZSBLbnBNZW51IGxpYnJhcnkiLAogICAgImtleXdvcmRzIjogICAgIFsibWVudSJdLAogICAgInR5cGUiOiAgICAgICAgICJhcHBsaWNhdGlvbiIsCiAgICAibGljZW5zZSI6ICAgICAgIk1JVCIsCiAgICAiYXV0aG9ycyI6ICAgICAgWwogICAgICAgIHsKICAgICAgICAgICAgIm5hbWUiOiAgICAgIktucGxhYnMiLAogICAgICAgICAgICAiaG9tZXBhZ2UiOiAiaHR0cDovL2tucGxhYnMuY29tIgogICAgICAgIH0sCiAgICAgICAgewogICAgICAgICAgICAibmFtZSI6ICAgICAiQ2hyaXN0b3BoZSBDb2V2b2V0IiwKICAgICAgICAgICAgImVtYWlsIjogICAgInN0b2ZAbm90ay5vcmciCiAgICAgICAgfSwKICAgICAgICB7CiAgICAgICAgICAgICJuYW1lIjogICAgICJTeW1mb255IENvbW11bml0eSIsCiAgICAgICAgICAgICJob21lcGFnZSI6ICJodHRwczovL2dpdGh1Yi5jb20vS25wTGFicy9LbnBNZW51QnVuZGxlL2NvbnRyaWJ1dG9ycyIKICAgICAgICB9CiAgICBdLAogICAgInJlcXVpcmUiOiAgICAgIHsKICAgICAgICAia25wbGFicy9rbnAtbWVudSI6ICAgICAgICAgIn4yLjAiLAogICAgICAgICJzeW1mb255L2ZyYW1ld29yay1idW5kbGUiOiAifjIuMCIKICAgIH0sCiAgICAiYXV0b2xvYWQiOiAgICAgewogICAgICAgICJwc3ItMCI6IHsgIktucFxcQXBwbGljYXRpb25cXE1lbnVBcHBsaWNhdGlvbiI6ICIiIH0KICAgIH0sCiAgICAidGFyZ2V0LWRpciI6ICJLbnAvQnVuZGxlL01lbnVCdW5kbGUiLAogICAgImV4dHJhIjogewogICAgICAgICJicmFuY2gtYWxpYXMiOiB7CiAgICAgICAgICAgICJkZXYtbWFzdGVyIjogIjIuMC54LWRldiIKICAgICAgICB9CiAgICB9LAogICAgIm1pbmltdW0tc3RhYmlsaXR5IjogImRldiIKfQ=="}
{"encoding": "base64", "content":"ewogICAgIm5hbWUiOiAicGF0cmlja3RhbG1hZGdlL2Jvb3RzdHJhcHBlciIs\nCiAgICAiZGVzY3JpcHRpb24iOiAiVHdpdHRlciBCb290c3RyYXAgbWFya3Vw\nIGdlbmVyYXRvciIsCiAgICAibGljZW5zZSI6ICJNSVQiLAogICAgImtleXdv\ncmRzIjogWwogICAgICAgICJib290c3RyYXAiLAogICAgICAgICJsYXJhdmVs\nIgogICAgXSwKICAgICJhdXRob3JzIjogWwogICAgICAgIHsKICAgICAgICAg\nICAgIm5hbWUiOiAiUGF0cmljayBUYWxtYWRnZSIsCiAgICAgICAgICAgICJl\nbWFpbCI6ICJwdGFsbWFkZ2VAZ21haWwuY29tIgogICAgICAgIH0sCiAgICAg\nICAgewogICAgICAgICAgICAibmFtZSI6ICJNYXhpbWUgRmFicmUiLAogICAg\nICAgICAgICAiZW1haWwiOiAiZWh0bmFtNkBnbWFpbC5jb20iCiAgICAgICAg\nfSwKICAgICAgICB7CiAgICAgICAgICAgICJuYW1lIjogIlBhdHJpY2sgUm9z\nZSIsCiAgICAgICAgICAgICJlbWFpbCI6ICJwanIwOTExMDI1QGdtYWlsLmNv\nbSIKICAgICAgICB9CiAgICBdLAogICAgInJlcXVpcmUiOiB7CiAgICAgICAg\nInBocCI6ICI+PTUuNC4wIiwKICAgICAgICAiaWxsdW1pbmF0ZS9odG1sIjog\nIn40LjIiLAogICAgICAgICJpbGx1bWluYXRlL3N1cHBvcnQiOiAifjQuMiIs\nCiAgICAgICAgImlsbHVtaW5hdGUvY29uZmlnIjogIn40LjIiLAogICAgICAg\nICJpbGx1bWluYXRlL3JvdXRpbmciOiAifjQuMiIsCiAgICAgICAgInR3YnMv\nYm9vdHN0cmFwIjogIn4zLjIiCiAgICB9LAogICAgInJlcXVpcmUtZGV2Ijog\newogICAgICAgICJtb2NrZXJ5L21vY2tlcnkiOiAiKiIsCiAgICAgICAgInBo\ncHNwZWMvcGhwc3BlYyI6ICIqIgogICAgfSwKICAgICJhdXRvbG9hZCI6IHsK\nICAgICAgICAicHNyLTQiOiB7CiAgICAgICAgICAgICJCb290c3RyYXBwZXJc\nXCI6ICJzcmNcXEJvb3RzdHJhcHBlciIKICAgICAgICB9CiAgICB9LAogICAg\nIm1pbmltdW0tc3RhYmlsaXR5IjogInN0YWJsZSIKfQoK\n"}

0 comments on commit 303e1ff

Please sign in to comment.