2019-02-17 11:34:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\DataMapper\ClientSettings;
|
|
|
|
use App\DataMapper\CompanySettings;
|
2019-04-24 12:01:40 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2019-02-17 11:34:46 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\DataMapper\BaseSettings
|
|
|
|
*/
|
|
|
|
class BaseSettingsTest extends TestCase
|
|
|
|
{
|
2019-04-24 12:01:40 +02:00
|
|
|
public function setUp() :void
|
2019-02-17 11:34:46 +01:00
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->settings = ClientSettings::defaults();
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testPropertyNamesExist()
|
|
|
|
{
|
|
|
|
$blank_object = new \stdClass;
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$updated_object = $this->migrate($blank_object);
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertTrue(property_exists($updated_object, 'size_id'));
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testPropertyNamesNotExist()
|
|
|
|
{
|
|
|
|
$blank_object = new \stdClass;
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$updated_object = $this->migrate($blank_object);
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertFalse(property_exists($updated_object, 'non_existent_prop'));
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function migrate(\stdClass $object) : \stdClass
|
|
|
|
{
|
|
|
|
foreach ($this->settings as $property => $value) {
|
|
|
|
if (!property_exists($object, $property)) {
|
|
|
|
$object->{$property} = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
}
|