Skip to content

Commit

Permalink
Fix bug where packages with a null description would cause a return t…
Browse files Browse the repository at this point in the history
…ype error

Also adds .editorconfig configuration for IDE compatibility
  • Loading branch information
robbieaverill committed Mar 1, 2022
1 parent 8fd1411 commit c676ce0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .editorconfig
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,json}]
indent_size = 2

[composer.json]
indent_size = 4
1 change: 1 addition & 0 deletions spec/Packagist/Api/Fixture/get_null_description.json
@@ -0,0 +1 @@
{"package":{"name":"sylius\/sylius","description":null,"time":"2013-01-18T20:48:01+00:00","maintainers":[{"name":"pjedrzejewski","email":"pjedrzejewski@diweb.pl"}],"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":"pjedrzejewski@diweb.pl","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":{"type":"zip","url":"https:\/\/api.github.com\/repos\/Sylius\/Sylius\/zipball\/1f0e49a6d4e9b6ab3a84cbd962f772c707461640","reference":"1f0e49a6d4e9b6ab3a84cbd962f772c707461640","shasum":""},"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":"pjedrzejewski@diweb.pl","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}}
9 changes: 8 additions & 1 deletion spec/Packagist/Api/Result/FactorySpec.php
Expand Up @@ -82,10 +82,17 @@ function it_creates_packages_with_dependents()
function it_creates_packages_with_null_source()
{
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_null_source.json'), true);

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

function it_creates_packages_with_null_description()
{
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_null_description.json'), true);
$result = $this->create($data);
$result->shouldHaveType('Packagist\Api\Result\Package');
$result->getDescription()->shouldBe('');
}

public function getMatchers(): array
{
return array(
Expand Down
2 changes: 2 additions & 0 deletions src/Packagist/Api/Result/Factory.php
Expand Up @@ -81,6 +81,8 @@ public function createPackageResults(array $package)
);
}

$package['description'] = (string) $package['description'] ?? '';

foreach ($package['versions'] as $branch => $version) {
if (isset($version['authors']) && $version['authors']) {
foreach ($version['authors'] as $key => $author) {
Expand Down

0 comments on commit c676ce0

Please sign in to comment.