alientronics/fleetany-attributes

View on GitHub
tests/acceptance/DynamoDbValueTest.php

Summary

Maintainability
A
55 mins
Test Coverage
<?php

namespace Tests\DynamoDb;

use Tests\AcceptanceValueTestCase;
use App\Entities\DynamoDb\ValueDynamoDb;

class DynamoDbValueTest extends AcceptanceValueTestCase
{

    /**
     * Creates the application.
     *
     * @return \Laravel\Lumen\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../../bootstrap/app.php';
        $app['config']['database.driver'] = 'dynamodb';
        return $app;
    }

    /**
     * Assert that a given where condition exists in the database.
     *
     * @param  string  $table
     * @param  array  $data
     * @param  string|null $onConnection
     * @return $this
     */
    protected function seeInDatabase($table, array $data, $onConnection = null)
    {
        if (!empty($data)) {
            foreach ($data as $index => $element) {
                if (is_numeric($element) && $index == "value") {
                    $data[$index] = (int) $element;
                }
            }
        }
        
        $Key = ValueDynamoDb::where($data);
        $Key = $Key->get()->first();
        
        if (empty($Key)) {
            return sprintf(
                'Unable to find row in database table [%s] that matched attributes [%s].',
                $table,
                json_encode($data)
            );
        } else {
            return true;
        }
    }
}