From b0fa2ccbf9aa6d48ec8d3434bfe08208ca5825c1 Mon Sep 17 00:00:00 2001 From: Antony Thorpe <1023740+AntonyThorpe@users.noreply.github.com> Date: Wed, 5 Jun 2024 19:26:30 +1200 Subject: [PATCH] Capitalise folder --- src/ArrayBulkLoaderSource.php | 6 +- src/BulkLoader.php | 122 +++++++-------------- src/BulkLoaderResult.php | 36 +++--- src/Consumer.php | 12 +- src/Utilities.php | 4 +- tests/BulkLoaderClearAbsentRecordsTest.php | 10 +- tests/BulkLoaderDeleteManyRecordsTest.php | 6 +- tests/BulkLoaderRelationTest.php | 2 +- tests/BulkLoaderTest.php | 2 +- tests/BulkLoaderUpdateRecordsTest.php | 10 +- tests/BulkLoaderUpsertManyRecordsTest.php | 6 +- tests/ConsumerModelTest.php | 6 +- tests/Fixtures/BulkLoaderRelationTest.yml | 12 ++ tests/Fixtures/BulkLoaderTest.yml | 7 ++ tests/Fixtures/Product.yml | 34 ++++++ tests/Fixtures/User.yml | 43 ++++++++ 16 files changed, 178 insertions(+), 140 deletions(-) create mode 100644 tests/Fixtures/BulkLoaderRelationTest.yml create mode 100644 tests/Fixtures/BulkLoaderTest.yml create mode 100644 tests/Fixtures/Product.yml create mode 100644 tests/Fixtures/User.yml diff --git a/src/ArrayBulkLoaderSource.php b/src/ArrayBulkLoaderSource.php index 275a3db..36a6d55 100755 --- a/src/ArrayBulkLoaderSource.php +++ b/src/ArrayBulkLoaderSource.php @@ -10,7 +10,6 @@ */ class ArrayBulkLoaderSource extends BulkLoaderSource { - public function __construct(protected array $data) { } @@ -20,14 +19,13 @@ public function getIterator(): ArrayIterator return new ArrayIterator($this->data); } - public function setData(array $data): static + public function setData(array $data): self { $this->data = $data; - return $this; } - public function getData() + public function getData(): array { return $this->data; } diff --git a/src/BulkLoader.php b/src/BulkLoader.php index a76d7ef..fe6af7d 100644 --- a/src/BulkLoader.php +++ b/src/BulkLoader.php @@ -39,39 +39,34 @@ class BulkLoader extends \SilverStripe\Dev\BulkLoader /** * Specify a colsure to be run on every imported record. - * @var function + * @var callable */ public $recordCallback; /** * Bulk loading source - * @var BulkLoaderSource */ - protected $source; + protected BulkLoaderSource $source; /** * Add new records while importing - * @var bool */ - protected $addNewRecords = true; + protected bool $addNewRecords = true; /** * The default behaviour for linking relations - * @var bool */ - protected $relationLinkDefault = true; + protected bool $relationLinkDefault = true; /** * The default behaviour creating relations - * @var bool */ - protected $relationCreateDefault = true; + protected bool $relationCreateDefault = true; /** * Determines whether pages should be published during loading - * @var bool */ - protected $publishPages = true; + protected bool $publishPages = true; /** * Cache the result of getMappableColumns @@ -82,7 +77,7 @@ class BulkLoader extends \SilverStripe\Dev\BulkLoader /** * Set the BulkLoaderSource for this BulkLoader. */ - public function setSource(BulkLoaderSource $source) + public function setSource(BulkLoaderSource $source) :static { $this->source = $source; return $this; @@ -90,19 +85,16 @@ public function setSource(BulkLoaderSource $source) /** * Get the BulkLoaderSource for this BulkLoader - * @return BulkLoaderSource $source */ - public function getSource() + public function getSource(): BulkLoaderSource { return $this->source; } /** * Set the default behaviour for linking existing relation objects. - * @param bool $default - * @return \AntonyThorpe\Consumer\BulkLoader */ - public function setRelationLinkDefault($default) + public function setRelationLinkDefault(bool $default): self { $this->relationLinkDefault = $default; return $this; @@ -110,10 +102,8 @@ public function setRelationLinkDefault($default) /** * Set the default behaviour for creating new relation objects. - * @param bool $default - * @return \AntonyThorpe\Consumer\BulkLoader */ - public function setRelationCreateDefault($default) + public function setRelationCreateDefault(bool $default): self { $this->relationCreateDefault = $default; return $this; @@ -121,10 +111,8 @@ public function setRelationCreateDefault($default) /** * Set pages to published upon upload - * @param bool $default - * @return \AntonyThorpe\Consumer\BulkLoader */ - public function setPublishPages($dopubilsh) + public function setPublishPages(bool $dopubilsh): self { $this->publishPages = $dopubilsh; return $this; @@ -140,9 +128,8 @@ public function deleteExistingRecords(): void /** * Get the DataList of objects this loader applies to. - * @return DataList */ - public function getDataList() + public function getDataList(): DataList { $class = $this->objectClass; return $class::get(); @@ -153,15 +140,13 @@ public function getDataList() * Useful to analyze the input and give the users a chance to influence * it through a UI. * @param string $filepath Absolute path to the file we're importing - * @return array See {@link self::processAll()} + * See {@link self::processAll()} */ - public function preview($filepath) + public function preview($filepath): array { - return null; + return []; } - - /** * Start loading of data * @param string $filepath @@ -179,11 +164,10 @@ public function load($filepath = null, $preview = false) /** * Import all records from the source - * @param string $filepath + * @param string $filepath * @param bool $preview - * @return BulkLoaderResult */ - protected function processAll($filepath, $preview = false) + protected function processAll($filepath, $preview = false): BulkLoaderResult { if (!$this->source) { user_error( @@ -200,15 +184,13 @@ protected function processAll($filepath, $preview = false) return $results; } - /** * Process a single record from source - * @param object $record + * @param array $record An map of the data, keyed by the header field defined in {@link self::$columnMap} * @param array $columnMap - * @param bool $preview * @param BulkLoaderResult $results - * @param string $preview set to true to prevent writing to the dataobject - * @return BulkLoaderResult + * @param bool $preview set to true to prevent writing to the dataobject + * @return BulkLoaderResult|null */ protected function processRecord($record, $columnMap, &$results, $preview = false) { @@ -316,9 +298,8 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals /** * Convert the record's keys to the appropriate columnMap keys - * @return array record */ - protected function columnMapRecord($record) + protected function columnMapRecord(array $record): array { $adjustedmap = $this->columnMap; $newrecord = []; @@ -335,10 +316,8 @@ protected function columnMapRecord($record) /** * Check if the given mapped record has the required data. - * @param array $mappedrecord - * @return bool */ - protected function hasRequiredData($mappedrecord) + protected function hasRequiredData(array $mappedrecord): bool { if (!is_array($mappedrecord) || $mappedrecord === [] || !array_filter($mappedrecord)) { return false; @@ -358,10 +337,8 @@ protected function hasRequiredData($mappedrecord) /** * Perform field transformation or setting of data on placeholder. - * @param DataObject $placeholder - * @param string $field */ - protected function transformField($placeholder, $field, mixed $value) + protected function transformField(DataObject $placeholder, string $field, mixed $value): void { $callback = isset($this->transforms[$field]['callback']) && is_callable($this->transforms[$field]['callback']) ? @@ -451,16 +428,14 @@ protected function transformField($placeholder, $field, mixed $value) /** * Detect if a given record field is a relation field. - * @param string $field - * @return bool */ - protected function isRelation($field) + protected function isRelation(string $field): bool { //get relation name from dot notation if (str_contains($field, '.')) { [$field, $columnName] = explode('.', $field); } - $has_ones = singleton($this->objectClass)->hasOne(); + $has_ones = DataObject::singleton($this->objectClass)->hasOne(); //check if relation is present in has ones return isset($has_ones[$field]); } @@ -468,10 +443,8 @@ protected function isRelation($field) /** * Given a record field name, find out if this is a relation name * and return the name - * @param string - * @return string */ - protected function getRelationName($recordField) + protected function getRelationName(string $recordField): string { $relationName = null; if (isset($this->relationCallbacks[$recordField])) { @@ -487,10 +460,8 @@ protected function getRelationName($recordField) /** * Find an existing objects based on one or more uniqueness columns * specified via {@link self::$duplicateChecks} - * @param array $record data - * @return mixed */ - public function findExistingObject(array $record) + public function findExistingObject(array $record): mixed { // checking for existing records (only if not already found) foreach ($this->duplicateChecks as $fieldName => $duplicateCheck) { @@ -536,9 +507,8 @@ public function findExistingObject(array $record) /** * Get the field-label mapping of fields that data can be mapped into. - * @return array */ - public function getMappableColumns() + public function getMappableColumns(): array { if ($this->mappableFields !== []) { return $this->mappableFields; @@ -556,14 +526,12 @@ public function getMappableColumns() /** * Generate a field-label list of fields that data can be mapped into. - * @param bool $includerelations - * @return array */ - public function scaffoldMappableFields($includerelations = true) + public function scaffoldMappableFields(bool $includerelations = true): array { $map = $this->getMappableFieldsForClass($this->objectClass); //set up 'dot notation' (Relation.Field) style mappings - if ($includerelations && ($has_ones = singleton($this->objectClass)->hasOne())) { + if ($includerelations && ($has_ones = DataObject::singleton($this->objectClass)->hasOne())) { foreach ($has_ones as $relationship => $type) { $fields = $this->getMappableFieldsForClass($type); foreach ($fields as $field => $title) { @@ -578,12 +546,10 @@ public function scaffoldMappableFields($includerelations = true) /** * Get the fields and labels for a given class - * @param string $class - * @return array fields */ - protected function getMappableFieldsForClass($class) + protected function getMappableFieldsForClass(string $class): array { - $singleton = singleton($class); + $singleton = DataObject::singleton($class); $fields = (array)$singleton->fieldLabels(false); foreach (array_keys($fields) as $field) { if (!$singleton->hasField($field)) { @@ -595,10 +561,8 @@ protected function getMappableFieldsForClass($class) /** * Format mapping field laabel - * @param string $relationship - * @param string $title */ - protected function formatMappingFieldLabel($relationship, $title) + protected function formatMappingFieldLabel(string $relationship, string $title): string { return sprintf("%s: %s", $relationship, $title); } @@ -632,12 +596,8 @@ public function preprocessChecks(): void /** * Update the dataobject with data from the external API - * - * @param array $apidata An array of arrays - * @param bool $preview Set to true to not write - * @return BulkLoaderResult */ - public function updateRecords(array $apidata, $preview = false) + public function updateRecords(array $apidata, bool $preview = false): BulkLoaderResult { $this->setSource(new ArrayBulkLoaderSource($apidata)); $this->addNewRecords = false; @@ -647,11 +607,8 @@ public function updateRecords(array $apidata, $preview = false) /** * Update/create many dataobjects with data from the external api - * - * @param bool $preview Set to true to not write - * @return BulkLoaderResult */ - public function upsertManyRecords(array $apidata, $preview = false) + public function upsertManyRecords(array $apidata, bool $preview = false): BulkLoaderResult { $this->setSource(new ArrayBulkLoaderSource($apidata)); $this->preprocessChecks(); @@ -660,11 +617,8 @@ public function upsertManyRecords(array $apidata, $preview = false) /** * Delete dataobjects that match to the API data - * - * @param bool $preview Set to true to not write - * @return BulkLoaderResult */ - public function deleteManyRecords(array $apidata, $preview = false) + public function deleteManyRecords(array $apidata, bool $preview = false): BulkLoaderResult { $this->setSource(new ArrayBulkLoaderSource($apidata)); $this->preprocessChecks(); @@ -709,10 +663,10 @@ public function deleteManyRecords(array $apidata, $preview = false) * @param array $apidata An array of arrays * @param string $key The key that matches the column within the Object Class * @param string $property_name The property name of the class that matches to the key from the API data - * @param bool $preview Set to true to not save + * @param bool $preview Set to true to skip saving * @return BulkLoaderResult */ - public function clearAbsentRecords(array $apidata, $key, $property_name, $preview = false) + public function clearAbsentRecords(array $apidata, string $key, string $property_name, bool $preview = false) { $results = BulkLoaderResult::create(); $modelClass = $this->objectClass; diff --git a/src/BulkLoaderResult.php b/src/BulkLoaderResult.php index 902a5f3..3dbcae7 100644 --- a/src/BulkLoaderResult.php +++ b/src/BulkLoaderResult.php @@ -14,20 +14,18 @@ class BulkLoaderResult extends BulkLoader_Result { /** * Keep track of skipped records. - * @var array */ - protected $skipped = []; + protected array $skipped = []; public function SkippedCount(): int { return count($this->skipped); } - /** - * @param string $message Reason for skipping + * Reason for skipping */ - public function addSkipped($message = null): void + public function addSkipped(string $message = ''): void { $this->skipped[] = [ 'Message' => $message @@ -35,8 +33,7 @@ public function addSkipped($message = null): void } /** - * Get an array of messages describing the result. - * @return array messages + * Get an array of messages describing the result */ public function getMessageList(): array { @@ -78,7 +75,7 @@ public function getMessageList(): array } /** - * Genenrate a human-readable result message. + * Genenrate a human-readable result message */ public function getMessage(): string { @@ -86,7 +83,7 @@ public function getMessage(): string } /** - * Provide a useful message type, based on result. + * Provide a useful message type, based on result */ public function getMessageType(): string { @@ -104,9 +101,8 @@ public function getMessageType(): string /** * Returns all created objects. Each object might * contain specific importer feedback in the "_BulkLoaderMessage" property. - * @return ArrayList */ - public function getCreated() + public function getCreated(): ArrayList { return $this->mapToArrayList($this->created); } @@ -160,7 +156,7 @@ public function getData(): ArrayList * @param DataObject $obj * @param string $message */ - public function addCreated($obj, $message = null): void + public function addCreated($obj, $message = ''): void { $this->created[] = $this->lastChange = $this->createResult($obj, $message); $this->lastChange['ChangeType'] = 'created'; @@ -170,7 +166,7 @@ public function addCreated($obj, $message = null): void * @param DataObject $obj * @param string $message */ - public function addUpdated($obj, $message = null, $additionalFields = null): void + public function addUpdated($obj, $message = '', $additionalFields = null): void { if ($changedFields = $this->getChangedFields($obj)) { // create additional fields to include with results @@ -196,10 +192,8 @@ public function addUpdated($obj, $message = null, $additionalFields = null): voi /** * Modelled on the getChangedFields of DataObject, with the addition of the variable's type - * @param DataObject $obj - * @return array The before/after changes of each field */ - protected function getChangedFields($obj) + protected function getChangedFields(DataObject $obj): array { $changedFields = $obj->getChangedFields(true, 2); foreach ($changedFields as $key => $value) { @@ -214,7 +208,7 @@ protected function getChangedFields($obj) * @param DataObject $obj * @param string $message */ - public function addDeleted($obj, $message = null): void + public function addDeleted($obj, $message = ''): void { $this->deleted[] = $this->lastChange = $this->createResult($obj, $message); $this->lastChange['ChangeType'] = 'deleted'; @@ -222,11 +216,8 @@ public function addDeleted($obj, $message = null): void /** * Create the Result for Deleted and Created items - * @param DataObject $obj - * @param String $message - * @return array */ - protected function createResult($obj, $message) + protected function createResult(DataObject $obj, string $message = ''): array { $data = $obj->toMap(); $data['_BulkLoaderMessage'] = $message; @@ -235,9 +226,8 @@ protected function createResult($obj, $message) /** * @param $arr array Either the created, updated or deleted items - * @return ArrayList */ - protected function mapToArrayList($arr) + protected function mapToArrayList($arr): ArrayList { $set = ArrayList::create(); foreach ($arr as $arrItem) { diff --git a/src/Consumer.php b/src/Consumer.php index 0b50776..58809a8 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -8,6 +8,9 @@ /** * Record the LastEdited date provided from external data + * @property string $Title provides a name against the API call + * @property string $ExternalLastEditedKey is the key that labels the last date the call was made + * @property Datetime $ExternalLastEdited is the last modified date from the external API data */ class Consumer extends DataObject { @@ -19,9 +22,6 @@ class Consumer extends DataObject /** * Save the maximum data using setExternalLastEdited method. Can use it to filter future calls to the API. * @config - * @property Title provides a name against the API call - * @property ExternalLastEditedKey is the key that labels the last date the call was made - * @property ExternalLastEdited is the last modified date from the external API data */ private static array $db = [ 'Title' => 'Varchar(250)', @@ -29,7 +29,10 @@ class Consumer extends DataObject 'ExternalLastEdited' => 'Datetime' ]; - public static function convertUnix2UTC($data): string + /** + * Convert a Unix date to a UTC + */ + public static function convertUnix2UTC(string $data): string { $string = preg_replace('/\D/', '', $data); $date = new DateTime(); @@ -63,7 +66,6 @@ public static function isTimestamp(string $string): bool /** * Set the ExternalLastEdited to the maximum last edited date - * @return $this */ public function setMaxExternalLastEdited(array $apidata): static { diff --git a/src/Utilities.php b/src/Utilities.php index a9e6837..a8bd62a 100644 --- a/src/Utilities.php +++ b/src/Utilities.php @@ -6,10 +6,8 @@ class Utilities { /** * get duplicates in an array - * @param array $data a list - * @return array The items that are duplicates */ - public static function getDuplicates($data = []): array + public static function getDuplicates(array $data = []): array { return array_unique(array_diff_assoc($data, array_unique($data))); } diff --git a/tests/BulkLoaderClearAbsentRecordsTest.php b/tests/BulkLoaderClearAbsentRecordsTest.php index f3551e1..800ba74 100644 --- a/tests/BulkLoaderClearAbsentRecordsTest.php +++ b/tests/BulkLoaderClearAbsentRecordsTest.php @@ -10,7 +10,7 @@ class BulkLoaderClearAbsentRecordsTest extends SapphireTest { - protected static $fixture_file = [__DIR__ . '/Fixtures/User.yml']; + protected static $fixture_file = ['Fixtures/User.yml']; protected $usesDatabase = true; @@ -18,7 +18,7 @@ class BulkLoaderClearAbsentRecordsTest extends SapphireTest public function testClearAbsentRecords(): void { - $apidata = json_decode($this->jsondata, true); + $apidata = (array) json_decode($this->jsondata, true); $results = UserBulkLoader::create(User::class)->clearAbsentRecords($apidata, 'guid', 'Guid'); // Check Results @@ -44,20 +44,20 @@ public function testClearAbsentRecords(): void $obj = User::get()->find('Email', 'Sincere@april.biz'); $this->assertSame( '1', - (string)$obj->Guid, + $obj->Guid, 'Sincere@april.biz Should not have changed the Guid field' ); } public function testClearAbsentRecordsWithPreview(): void { - $apidata = json_decode($this->jsondata, true); + $apidata = (array) json_decode($this->jsondata, true); UserBulkLoader::create(User::class)->clearAbsentRecords($apidata, 'guid', 'Guid', true); $item = User::get()->find('Email', 'LocalOnly@local.net'); $this->assertSame( '99999', - (string)$item->Guid, + $item->Guid, 'LocalOnly@local.net Guid property not updated' ); } diff --git a/tests/BulkLoaderDeleteManyRecordsTest.php b/tests/BulkLoaderDeleteManyRecordsTest.php index e21cd37..b33b968 100644 --- a/tests/BulkLoaderDeleteManyRecordsTest.php +++ b/tests/BulkLoaderDeleteManyRecordsTest.php @@ -8,7 +8,7 @@ class BulkLoaderDeleteManyRecordsTest extends SapphireTest { - protected static $fixture_file = [__DIR__ . '/Fixtures/User.yml']; + protected static $fixture_file = ['Fixtures/User.yml']; protected static $extra_dataobjects = [User::class]; @@ -19,7 +19,7 @@ public function testDeleteManyRecords(): void $this->assertTrue($shanna->exists(), 'Shanna exists in User'); $this->assertTrue($nathan->exists(), 'Nathan exists in User'); - $apidata = json_decode($this->jsondata_to_delete, true); + $apidata = (array) json_decode($this->jsondata_to_delete, true); $results = UserBulkLoader::create(User::class)->deleteManyRecords($apidata); // Check Results @@ -73,7 +73,7 @@ public function testDeleteManyRecords(): void public function testDeleteManyWithPreview(): void { $original_count = User::get()->count(); - $apidata = json_decode($this->jsondata_to_delete, true); + $apidata = (array) json_decode($this->jsondata_to_delete, true); UserBulkLoader::create(User::class)->deleteManyRecords($apidata, true); $this->assertEquals( diff --git a/tests/BulkLoaderRelationTest.php b/tests/BulkLoaderRelationTest.php index 46e6ebf..787b758 100644 --- a/tests/BulkLoaderRelationTest.php +++ b/tests/BulkLoaderRelationTest.php @@ -11,7 +11,7 @@ class BulkLoaderRelationTest extends SapphireTest { - protected static $fixture_file = [__DIR__ . '/Fixtures/BulkLoaderRelationTest.yml']; + protected static $fixture_file = ['Fixtures/BulkLoaderRelationTest.yml']; protected static $extra_dataobjects = [ Course::class, diff --git a/tests/BulkLoaderTest.php b/tests/BulkLoaderTest.php index 50e8cea..07da2dc 100644 --- a/tests/BulkLoaderTest.php +++ b/tests/BulkLoaderTest.php @@ -10,7 +10,7 @@ class BulkLoaderTest extends SapphireTest { - protected static $fixture_file = [__DIR__ . '/Fixtures/BulkLoaderTest.yml']; + protected static $fixture_file = ['Fixtures/BulkLoaderTest.yml']; protected static $extra_dataobjects = [ Person::class, diff --git a/tests/BulkLoaderUpdateRecordsTest.php b/tests/BulkLoaderUpdateRecordsTest.php index c1f4d27..d7b01e6 100644 --- a/tests/BulkLoaderUpdateRecordsTest.php +++ b/tests/BulkLoaderUpdateRecordsTest.php @@ -12,8 +12,8 @@ class BulkLoaderUpdateRecordsTest extends SapphireTest { protected static $fixture_file = [ - __DIR__ . '/Fixtures/User.yml', - __DIR__ . '/Fixtures/Product.yml' + 'Fixtures/User.yml', + 'Fixtures/Product.yml' ]; protected static $extra_dataobjects = [ @@ -35,7 +35,7 @@ public function setUp(): void public function testUpdateRecords(): void { - $apidata = json_decode($this->jsondata1, true); + $apidata = (array) json_decode($this->jsondata1, true); $results = UserBulkLoader::create(User::class)->updateRecords($apidata); // Check Results @@ -90,7 +90,7 @@ public function testUpdateRecords(): void public function testUpdateRecordsWithPreview(): void { $original_count = User::get()->count(); - $apidata = json_decode($this->jsondata1, true); + $apidata = (array) json_decode($this->jsondata1, true); UserBulkLoader::create(User::class)->updateRecords($apidata, true); $this->assertEquals( @@ -126,7 +126,7 @@ public function testUpdateRecordsWithPreview(): void public function testUpdateRecordsWhenDataobjectExtendsPage(): void { - $apidata = json_decode($this->jsondata2, true); + $apidata = (array) json_decode($this->jsondata2, true); $loader = ProductBulkLoader::create(Product::class); $loader->transforms = [ 'Title' => [ diff --git a/tests/BulkLoaderUpsertManyRecordsTest.php b/tests/BulkLoaderUpsertManyRecordsTest.php index 52c09ce..db3baaf 100644 --- a/tests/BulkLoaderUpsertManyRecordsTest.php +++ b/tests/BulkLoaderUpsertManyRecordsTest.php @@ -8,13 +8,13 @@ class BulkLoaderUpsertManyRecordsTest extends SapphireTest { - protected static $fixture_file = [__DIR__ . '/Fixtures/User.yml']; + protected static $fixture_file = ['Fixtures/User.yml']; protected static $extra_dataobjects = [User::class]; public function testUpsertManyRecords(): void { - $apidata = json_decode($this->jsondata_to_upsert, true); + $apidata = (array) json_decode($this->jsondata_to_upsert, true); $results = UserBulkLoader::create(User::class)->upsertManyRecords($apidata); // Check Results @@ -71,7 +71,7 @@ public function testUpsertManyRecords(): void public function testUpsertManyRecordsWithPreview(): void { - $apidata = json_decode($this->jsondata_to_upsert, true); + $apidata = (array) json_decode($this->jsondata_to_upsert, true); UserBulkLoader::create(User::class)->upsertManyRecords($apidata, true); $remains = User::get()->find('Email', 'Sincere@april.biz'); diff --git a/tests/ConsumerModelTest.php b/tests/ConsumerModelTest.php index 8323afe..1a21b6e 100644 --- a/tests/ConsumerModelTest.php +++ b/tests/ConsumerModelTest.php @@ -9,7 +9,7 @@ class ConsumerModelTest extends SapphireTest { public function testCreateUpdate(): void { - $apidata = json_decode($this->jsondata, true); + $apidata = (array) json_decode($this->jsondata, true); $dataobject = Consumer::create( [ 'Title' => 'ProductUpdate', @@ -38,7 +38,7 @@ public function testCreateUpdate(): void public function testCreateUpdateWithUnixDateFormat(): void { - $apidata = json_decode($this->jsondata2, true); + $apidata = (array) json_decode($this->jsondata2, true); $dataobject = Consumer::create( [ 'Title' => 'ProductUpdate2', @@ -57,7 +57,7 @@ public function testCreateUpdateWithUnixDateFormat(): void public function testCreateUpdateWithUnixDateFormatInMilliseconds(): void { - $apidata = json_decode($this->jsondata3, true); + $apidata = (array) json_decode($this->jsondata3, true); $dataobject = Consumer::create( [ 'Title' => 'ProductUpdate3', diff --git a/tests/Fixtures/BulkLoaderRelationTest.yml b/tests/Fixtures/BulkLoaderRelationTest.yml new file mode 100644 index 0000000..a390b66 --- /dev/null +++ b/tests/Fixtures/BulkLoaderRelationTest.yml @@ -0,0 +1,12 @@ +AntonyThorpe\Consumer\Tests\Model\Course: + math101: + Title: 'Math 101' + tech102: + Title: 'Tech 102' + mus103: + Title: 'Music 103' + +AntonyThorpe\Consumer\Tests\Model\CourseSelection: + tech102: + Course: =>AntonyThorpe\Consumer\Tests\Model\Course.tech102 + Term: 3 diff --git a/tests/Fixtures/BulkLoaderTest.yml b/tests/Fixtures/BulkLoaderTest.yml new file mode 100644 index 0000000..17e7d09 --- /dev/null +++ b/tests/Fixtures/BulkLoaderTest.yml @@ -0,0 +1,7 @@ +AntonyThorpe\Consumer\Tests\Model\Country: + nz: + Title: New Zealand + Code: NZ + au: + Title: Australia + Code: AU diff --git a/tests/Fixtures/Product.yml b/tests/Fixtures/Product.yml new file mode 100644 index 0000000..96cd263 --- /dev/null +++ b/tests/Fixtures/Product.yml @@ -0,0 +1,34 @@ +AntonyThorpe\Consumer\Tests\Model\Product: + products: + Title: Shop + URLSegment: shop + Content:

This is some content

+ ShowInMenus: 1 + ShowInSearch: 1 + pm1: + InternalItemID: SPACE + Title: Space - Beyond the Solar System + BasePrice: 99.99 + URLSegment: alien + Content:

This is some content

+ Parent: =>AntonyThorpe\Consumer\Tests\Model\Product.products + ShowInMenus: 0 + ShowInSearch: 0 + pm2: + InternalItemID: BOOK + Title: Book of Bad Smells + BasePrice: 12345.89 + URLSegment: book + Content:

This is some content

+ Parent: =>AntonyThorpe\Consumer\Tests\Model\Product.products + ShowInMenus: 1 + ShowInSearch: 1 + pm3: + InternalItemID: CFIRE + Title: Chariot of Fire will need to be updated along with the default selling price + BasePrice: 100.00 + URLSegment: chariot + Content:

This is some content

+ Parent: =>AntonyThorpe\Consumer\Tests\Model\Product.products + ShowInMenus: 1 + ShowInSearch: 0 diff --git a/tests/Fixtures/User.yml b/tests/Fixtures/User.yml new file mode 100644 index 0000000..eb4d26f --- /dev/null +++ b/tests/Fixtures/User.yml @@ -0,0 +1,43 @@ +AntonyThorpe\Consumer\Tests\Model\User: + um1: + Name: Will Be Updated + UserName: Will Be Updated + Email: Sincere@april.biz + Phone: Will Be Updated + Website: Will Be Updated + Guid: 1 + um2: + Name: Will Be Updated + UserName: Will Be Updated + Email: Shanna@melissa.tv + Phone: Will Be Updated + Website: Will Be Updated + Guid: 2 + um3: + Name: Clementine Will be changed + UserName: Samantha + Email: Nathan@yesenia.net + Phone: 1-463-123-4447 + Website: ramiro.info + Guid: 3 + um4: + Name: Patricia Lebsack + UserName: Karianne + Email: Julianne.OConner@kory.org + Phone: 493-170-9623 x156 + Website: kale.biz + Guid: 4 + um5: + Name: Chelsey Dietrich + UserName: Kamren + Email: Lucio_Hettinger@annie.ca + Phone: (254)954-1289 + Website: demarco.info + Guid: 5 + um6: + Name: Will Not Be Found In The External API or in Consumer Subclass + UserName: LocalOnly + Email: LocalOnly@local.net + Phone: 954-1289 + Website: local.info + Guid: 99999