Skip to content

Commit

Permalink
Merge pull request #87 from spatie/fix-null-values
Browse files Browse the repository at this point in the history
Fix null values
  • Loading branch information
Gummibeer authored Aug 7, 2019
2 parents de66a62 + fc204c7 commit ad8d92d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ before_script:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

script:
- phpunit --coverage-text --coverage-clover=coverage.clover
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"require-dev": {
"graham-campbell/analyzer": "^2.1.1",
"league/flysystem": "^1.0",
"phpunit/phpunit": "^6.0",
"phpunit/phpunit": "^6.0|^7.0|^8.0",
"scrutinizer/ocular": "^1.5",
"symfony/console": "^3.2",
"symfony/css-selector": "^3.2",
Expand Down
4 changes: 3 additions & 1 deletion generator/templates/static/BaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function getType(): string

public function setProperty(string $property, $value)
{
$this->properties[$property] = $value;
if ($value !== null) {
$this->properties[$property] = $value;
}

return $this;
}
Expand Down
4 changes: 3 additions & 1 deletion src/BaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function getType(): string

public function setProperty(string $property, $value)
{
$this->properties[$property] = $value;
if ($value !== null) {
$this->properties[$property] = $value;
}

return $this;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/BaseTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public function it_can_set_and_retrieve_a_property()
$this->assertEquals(['foo' => 'bar'], $type->getProperties());
}

/** @test */
public function it_can_not_set_a_null_value()
{
$type = new DummyType();

$type->setProperty('foo', null);

$this->assertEquals([], $type->getProperties());
}

/** @test */
public function it_can_conditionally_set_and_retrieve_a_property()
{
Expand Down

0 comments on commit ad8d92d

Please sign in to comment.