Skip to content

Commit

Permalink
Merge pull request #4 from chillu/pulls/skip-missing-dist-factory
Browse files Browse the repository at this point in the history
Allow empty 'dist' in Result\Factory
  • Loading branch information
pilot committed Aug 30, 2013
2 parents 6b3abed + 9b96f93 commit 0632200
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions spec/Packagist/Api/Fixture/get_nodist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"package":{"name":"sylius\/sylius","description":"Modern ecommerce for Symfony2","time":"2013-01-18T20:48:01+00:00","maintainers":[{"name":"pjedrzejewski","email":"[email protected]"}],"versions":{"dev-master":{"name":"sylius\/sylius","description":"Modern ecommerce for Symfony2","keywords":[],"homepage":"http:\/\/sylius.org","version":"dev-master","version_normalized":"9999999-dev","license":["MIT"],"authors":[{"name":"Pawe\u0142 J\u0119drzejewski","email":"[email protected]","homepage":"http:\/\/pjedrzejewski.com"},{"name":"Sylius project","homepage":"http:\/\/sylius.org"},{"name":"Community contributions","homepage":"http:\/\/github.com\/Sylius\/Sylius\/contributors"}],"source":{"type":"git","url":"https:\/\/github.com\/Sylius\/Sylius.git","reference":"1f0e49a6d4e9b6ab3a84cbd962f772c707461640"},"dist":null,"type":"library","time":"2013-03-17T12:27:32+00:00","autoload":{"psr-0":{"Context":"features\/"}},"extra":{"symfony-app-dir":"sylius","symfony-web-dir":"web"},"require":{"php":">=5.3.3","doctrine\/orm":">=2.2.3,<2.4-dev","doctrine\/doctrine-fixtures-bundle":"*","twig\/extensions":"1.0.*","symfony\/assetic-bundle":"2.1.*","sylius\/core-bundle":"0.1.*","sylius\/web-bundle":"0.1.*","symfony\/symfony":">=2.2,<2.3-dev","doctrine\/doctrine-bundle":"1.2.*","symfony\/swiftmailer-bundle":"2.2.*","symfony\/monolog-bundle":"2.2.*","sensio\/distribution-bundle":"2.2.*","mathiasverraes\/money":"dev-master@dev"},"require-dev":{"behat\/behat":"2.4.*","behat\/symfony2-extension":"*","behat\/mink-extension":"*","behat\/mink-browserkit-driver":"*","phpspec\/phpspec2":"dev-develop","behat\/mink-selenium2-driver":"*"}},"dev-checkout":{"name":"sylius\/sylius","description":"Modern ecommerce for Symfony2","keywords":[],"homepage":"","version":"dev-checkout","version_normalized":"dev-checkout","license":["MIT"],"authors":[{"name":"Pawe\u0142 J\u0119drzejewski","email":"[email protected]","homepage":"http:\/\/pjedrzejewski.com"},{"name":"Sylius project","homepage":"http:\/\/sylius.org"},{"name":"Community contributions","homepage":"http:\/\/github.com\/Sylius\/Sylius\/contributors"}],"source":{"type":"git","url":"https:\/\/github.com\/Sylius\/Sylius.git","reference":"cb0a489db41707d5df078f1f35e028e04ffd9e8e"},"dist":{"type":"zip","url":"https:\/\/api.github.com\/repos\/Sylius\/Sylius\/zipball\/cb0a489db41707d5df078f1f35e028e04ffd9e8e","reference":"cb0a489db41707d5df078f1f35e028e04ffd9e8e","shasum":""},"type":"library","time":"2013-03-01T22:22:37+00:00","autoload":{"psr-0":{"Context":"features\/"}},"extra":{"symfony-app-dir":"sylius","symfony-web-dir":"web"},"require":{"php":">=5.3.3","symfony\/symfony":">=2.2,<2.3-dev","doctrine\/orm":">=2.2.3,<2.4-dev","doctrine\/doctrine-bundle":"1.2.*","doctrine\/doctrine-fixtures-bundle":"*","twig\/extensions":"1.0.*","symfony\/assetic-bundle":"2.1.*","symfony\/swiftmailer-bundle":"2.2.*","symfony\/monolog-bundle":"2.2.*","sensio\/distribution-bundle":"2.2.*","sylius\/core-bundle":"0.1.*","sylius\/web-bundle":"0.1.*","mathiasverraes\/money":"dev-master@dev"},"require-dev":{"behat\/behat":"2.4.*","behat\/symfony2-extension":"*","behat\/mink-extension":"*","behat\/mink-browserkit-driver":"*","phpspec\/phpspec2":"dev-develop","behat\/mink-selenium2-driver":"*"}}},"type":"library","repository":"https:\/\/github.com\/Sylius\/Sylius.git","downloads":{"total":41,"monthly":30,"daily":0},"favers":0}}
7 changes: 7 additions & 0 deletions spec/Packagist/Api/Result/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ function it_creates_package_names()
));
}

function it_creates_packages_with_missing_optional_data()
{
$data = json_decode(FixtureLoader::load('get_nodist.json'), true);

$this->create($data)->shouldHaveType('Packagist\Api\Result\Package');
}

static public function getMatchers()
{
return array(
Expand Down
12 changes: 8 additions & 4 deletions src/Packagist/Api/Result/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,26 @@ public function createPackageResults(array $package)
{
$created = array();

if (isset($package['maintainers'])) {
if (isset($package['maintainers']) && $package['maintainers']) {
foreach ($package['maintainers'] as $key => $maintainer) {
$package['maintainers'][$key] = $this->createResult('Packagist\Api\Result\Package\Maintainer', $maintainer);
}
}

$package['downloads'] = $this->createResult('Packagist\Api\Result\Package\Downloads', $package['downloads']);
if (isset($package['downloads']) && $package['downloads']) {
$package['downloads'] = $this->createResult('Packagist\Api\Result\Package\Downloads', $package['downloads']);
}

foreach ($package['versions'] as $branch => $version) {
if (isset($version['authors'])) {
if (isset($version['authors']) && $version['authors']) {
foreach ($version['authors'] as $key => $author) {
$version['authors'][$key] = $this->createResult('Packagist\Api\Result\Package\Author', $author);
}
}
$version['source'] = $this->createResult('Packagist\Api\Result\Package\Source', $version['source']);
$version['dist'] = $this->createResult('Packagist\Api\Result\Package\Dist', $version['dist']);
if (isset($version['dist']) && $version['dist']) {
$version['dist'] = $this->createResult('Packagist\Api\Result\Package\Dist', $version['dist']);
}

$package['versions'][$branch] = $this->createResult('Packagist\Api\Result\Package\Version', $version);
}
Expand Down

0 comments on commit 0632200

Please sign in to comment.