Skip to content

Commit

Permalink
Merge pull request #214 from podio-community/213-fix-exceptions-on-save
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sc committed Oct 5, 2021
2 parents 1182e8a + c9c8080 commit 87a1d18
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[6.1.0](#v6.1.0) / Unreleased
==================
* Bugfix: In some cases errors where raised, instead of defined exceptions if preconditions for save operations were missing (see #213).

[6.0.1](#v6.0.1) / 2021-09-24
==================
Expand Down
2 changes: 1 addition & 1 deletion models/PodioItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function save($options = array())
$this->item_id = $new->item_id;
return $this;
} else {
throw new PodioMissingRelationshipError('{"error_description":"Item is missing relationship to app"}', null, null);
throw new PodioMissingRelationshipError('{"error_description":"Item is missing relationship to app", "request": {}}', null, null);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/field/PodioItemField.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function save($options = array())
{
$relationship = $this->relationship();
if (!$relationship) {
throw new PodioMissingRelationshipError('{"error_description":"Field is missing relationship to item"}', null, null);
throw new PodioMissingRelationshipError('{"error_description":"Field is missing relationship to item", "request": {}}', null, null);
}
if (!$this->id && !$this->external_id) {
throw new PodioDataIntegrityError('Field must have id or external_id set.');
Expand Down
9 changes: 8 additions & 1 deletion tests/PodioAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ class PodioAppTest extends TestCase
public function test_performance_large_app(): void
{
$start = time();
$appString = file_get_contents(__DIR__.'/fixtures/large-app.json');
$appString = file_get_contents(__DIR__ . '/fixtures/large-app.json');
$appJson = json_decode($appString, true);
new PodioApp(array_merge($appJson, ['__api_values' => true]));
$duration = time() - $start;
$this->assertLessThan(5, $duration, "creating large app should be fast!");
}

public function test_app_with_id(): void
{
$app = new PodioApp(12345);
$this->assertEquals(12345, $app->app_id);
$this->assertEquals(12345, $app->id);
}
}
29 changes: 29 additions & 0 deletions tests/PodioItemFieldTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Podio\Tests;

require __DIR__ . '/../vendor/autoload.php';

use PHPUnit\Framework\TestCase;
use PodioItem;
use PodioItemFieldCollection;

class PodioItemFieldTest extends TestCase
{
public function test_save_should_throw_error_if_relationship_to_item_missing(): void
{
$this->expectException('PodioMissingRelationshipError');
$itemField = new \PodioItemField();
$itemField->save();
}

public function test_save_should_throw_error_if_external_id_missing(): void
{
$this->expectException('PodioDataIntegrityError');
$itemField = new \PodioItemField();
// assure relationship to item is present:
new PodioItem(['fields' => new PodioItemFieldCollection([$itemField])]);

$itemField->save();
}
}
38 changes: 38 additions & 0 deletions tests/PodioItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Podio\Tests;

require __DIR__ . '/../vendor/autoload.php';

use PHPUnit\Framework\TestCase;
use PodioApp;
use PodioItem;
use PodioItemFieldCollection;
use PodioTextItemField;

class PodioItemTest extends TestCase
{
public function test_create_item(): void
{
$item = new PodioItem([
'app' => new PodioApp(1234),
'fields' => new PodioItemFieldCollection([
new PodioTextItemField(["external_id" => "title", "values" => "TEST"]),
])
]);

$this->assertEquals(1234, $item->app->id);
}


public function test_save_should_throw_error_if_app_id_missing(): void
{
$this->expectException('PodioMissingRelationshipError');
$item = new PodioItem([
'fields' => new PodioItemFieldCollection([
new PodioTextItemField(["external_id" => "title", "values" => "TEST"]),
])
]);
$item->save();
}
}

0 comments on commit 87a1d18

Please sign in to comment.