Skip to content

Commit

Permalink
Add empty package when storing namespaced object in vehicle (#201)
Browse files Browse the repository at this point in the history
Objects stored in an xPDOVehicle from classes with a namespace should not add a package containing that namespace to the vehicle payload. Doing so causes unnecessary attempts to load classes with the namespace prefixed to the already fully-qualified classname.
  • Loading branch information
opengeek authored Apr 25, 2021
1 parent 5a5a3c0 commit c4f7bc6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/xPDO/Transport/xPDOObjectVehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public function put(& $transport, & $object, $attributes = array ()) {
parent :: put($transport, $object, $attributes);
if (is_object($object)) {
if (!isset ($this->payload['package'])) {
if ($object instanceof xPDOObject) {
if ($object instanceof xPDOObject && strpos(get_class($object), '\\') === false) {
$packageName = $object->_package;
} else {
$packageName = '';
Expand Down
2 changes: 1 addition & 1 deletion src/xPDO/Transport/xPDOVehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function put(& $transport, & $object, $attributes = array ()) {
$this->payload['guid'] = md5(uniqid(rand(), true));
}
if (!isset ($this->payload['package'])) {
if ($object instanceof xPDOObject) {
if ($object instanceof xPDOObject && strpos(get_class($object), '\\') === false) {
$packageName = $object->_package;
} else {
$packageName = '';
Expand Down
1 change: 1 addition & 0 deletions test/complete.phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<file>./xPDO/Test/Cache/xPDOCacheDbTest.php</file>
<file>./xPDO/Test/Compression/xPDOZipTest.php</file>
<file>./xPDO/Test/Transport/xPDOTransportTest.php</file>
<file>./xPDO/Test/Transport/xPDOVehicleTest.php</file>
<file>./xPDO/Test/PSR4/xPDOTest.php</file>
<file>./xPDO/Test/TearDownTest.php</file>
</testsuite>
Expand Down
1 change: 1 addition & 0 deletions test/mysql.phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<file>./xPDO/Test/Cache/xPDOCacheDbTest.php</file>
<file>./xPDO/Test/Compression/xPDOZipTest.php</file>
<file>./xPDO/Test/Transport/xPDOTransportTest.php</file>
<file>./xPDO/Test/Transport/xPDOVehicleTest.php</file>
<file>./xPDO/Test/PSR4/xPDOTest.php</file>
<file>./xPDO/Test/TearDownTest.php</file>
</testsuite>
Expand Down
1 change: 1 addition & 0 deletions test/pgsql.phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<file>./xPDO/Test/Cache/xPDOCacheDbTest.php</file>
<file>./xPDO/Test/Compression/xPDOZipTest.php</file>
<file>./xPDO/Test/Transport/xPDOTransportTest.php</file>
<file>./xPDO/Test/Transport/xPDOVehicleTest.php</file>
<file>./xPDO/Test/PSR4/xPDOTest.php</file>
<file>./xPDO/Test/TearDownTest.php</file>
</testsuite>
Expand Down
1 change: 1 addition & 0 deletions test/sqlite.phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<file>./xPDO/Test/Cache/xPDOCacheDbTest.php</file>
<file>./xPDO/Test/Compression/xPDOZipTest.php</file>
<file>./xPDO/Test/Transport/xPDOTransportTest.php</file>
<file>./xPDO/Test/Transport/xPDOVehicleTest.php</file>
<file>./xPDO/Test/PSR4/xPDOTest.php</file>
<file>./xPDO/Test/TearDownTest.php</file>
</testsuite>
Expand Down
32 changes: 32 additions & 0 deletions test/xPDO/Test/Transport/xPDOVehicleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/*
* The file is part of the xPDO package.
*
* Copyright (c) Jason Coward <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace xPDO\Test\Transport;


use xPDO\Test\Sample\xPDOSample;
use xPDO\TestCase;
use xPDO\Transport\xPDOObjectVehicle;
use xPDO\Transport\xPDOTransport;

class xPDOVehicleTest extends TestCase
{
public function testPutDoesNotAddPackageForNamespacedClass()
{
$transport = new xPDOTransport($this->xpdo, uniqid('transport-'), self::$properties['xpdo_test_path'] . 'fs/transport/');

$object = $this->xpdo->newObject(xPDOSample::class);

$vehicle = new xPDOObjectVehicle();
$vehicle->put($transport, $object);

$this->assertEmpty($vehicle->payload['package']);
}
}

0 comments on commit c4f7bc6

Please sign in to comment.