add function for easy filling test fixtures with datas from db (export)

This commit is contained in:
Dario Rekowski on RockPI 2021-04-14 10:00:44 +00:00
parent afc01fd9f4
commit 57144956b5
2 changed files with 45 additions and 36 deletions

View File

@ -0,0 +1,28 @@
<?php
namespace App\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class BaseTestFixture extends TestFixture
{
protected function sqlEntrysToRecords($sql_entries, $fields) {
$field_array_keys = array_keys($fields);
$records = [];
foreach($sql_entries as $sql_entry) {
$record = [];
foreach($sql_entry as $i => $value) {
$field = $field_array_keys[$i];
$record[$field] = $value;
}
$records[] = $record;
}
}
}

View File

@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* StateUsersFixture
*/
class StateUsersFixture extends TestFixture
class StateUsersFixture extends BaseTestFixture
{
/**
* Fields
@ -15,22 +15,26 @@ class StateUsersFixture extends TestFixture
*/
// @codingStandardsIgnoreStart
public $fields = [
'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'index_id' => ['type' => 'smallinteger', 'length' => 6, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'group_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'index_id' => ['type' => 'smallinteger', 'length' => 6, 'unsigned' => false, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null],
'group_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'public_key' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'email' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null],
'first_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null],
'last_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null],
'email' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'first_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'last_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'username' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'disabled' => ['type' => 'tinyinteger', 'length' => 4, 'unsigned' => false, 'null' => true, 'default' => '0', 'comment' => '', 'precision' => null],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
'public_key' => ['type' => 'unique', 'columns' => ['public_key'], 'length' => []],
],
'_options' => [
'engine' => 'InnoDB',
'collation' => 'utf8_bin'
'collation' => 'utf8mb4_unicode_ci'
],
];
// @codingStandardsIgnoreEnd
/**
* Init method
@ -39,35 +43,12 @@ class StateUsersFixture extends TestFixture
*/
public function init()
{
$this->records = [
[
'id' => 1,
'index_id' => 0,
'group_id' => 0,
'public_key' => hex2bin('94ae135b93cd9f33752b4e55c41903a3faa13a75bb90bfd411ea1d4a1a5e711f'),
'email' => '***REMOVED***',
'first_name' => 'Dario',
'last_name' => 'Rekowski'
],
[
'id' => 4,
'index_id' => 0,
'group_id' => 0,
'public_key' => hex2bin('8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d'),
'email' => 'dariofrodo@gmx.de',
'first_name' => 'Dario',
'last_name' => 'Frodo'
],
[
'id' => 11,
'index_id' => 0,
'group_id' => 0,
'public_key' => hex2bin('61b923c218cb63a64a8c62f3860121283b9577f374d0a31590ba02cdc2912999'),
'email' => 'em741@gmx.de',
'first_name' => 'Dario',
'last_name' => 'Rekowski'
],
$sql_entrys = [
[1, 0, 0, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0],
[3, 0, 0, 0x131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6, 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0],
[4, 0, 0, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0]
];
$this->records = $this->sqlEntrysToRecords($sql_entrys, $this->fields);
parent::init();
}
}