Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/Factory/IncidentFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace App\Test\Factory;

use CakephpFixtureFactories\Factory\BaseFactory;
use Faker\Generator;

class IncidentFactory extends BaseFactory
{
/**
* Defines the Table Registry used to generate entities with
* @return string
*/
protected function getRootTableRegistryName(): string
{
return 'Incidents';
}

/**
* Defines the default values of you factory. Useful for
* not nullable fields.
* Use the patchData method to set the field values.
* You may use methods of the factory here
*/
protected function setDefaultTemplate(): void
{
$this->setDefaultData(function(Generator $faker) {
return [
'type' => 'Other',
'details' => $faker->sentence(),
];
});
}
}
17 changes: 8 additions & 9 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Cake\Database\Connection;
use Cake\Database\Driver\Mysql;
use Cake\Datasource\ConnectionManager;
use Cake\Routing\Router;
use Migrations\TestSuite\Migrator;

/**
Expand All @@ -35,21 +34,21 @@
require dirname(__DIR__) . '/vendor/autoload.php';

define('PHPUNIT_TESTSUITE', true);
require dirname(__DIR__) . '/config/bootstrap.php';

if (empty($_SERVER['HTTP_HOST']) && !Configure::read('App.fullBaseUrl')) {
Configure::write('App.fullBaseUrl', 'http://localhost');
// config/bootstrap.php ran above before HTTP_HOST was set, so Router never picked up
// a base URL. Set it explicitly here so Router::url(..., true) generates valid absolute URLs.
Router::fullBaseUrl('http://localhost');

// Under the CLI SAPI there is no HTTP_HOST, so config/bootstrap.php would compute an
// empty Router base URL ('http://'). Router::url(..., true) then yields malformed URLs
// like 'http:///users/login', which parse_url() rejects, breaking the unauthenticated
// redirect (it collapses to '/'). Set a host before bootstrapping so the base URL is valid.
if (empty($_SERVER['HTTP_HOST'])) {
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['SERVER_NAME'] = 'test.zuluru.org';
$_SERVER['HTTP_HOST'] = 'test.zuluru.org';
$_SERVER['REQUEST_SCHEME'] = 'https';
$_SERVER['HTTPS'] = 1;
$_SERVER['HTTPS'] = 'on';
}

require dirname(__DIR__) . '/config/bootstrap.php';

// DebugKit skips settings these connection config if PHP SAPI is CLI / PHPDBG.
// But since PagesControllerTest is run with debug enabled and DebugKit is loaded
// in application, without setting up these config DebugKit errors out.
Expand Down
Loading