Check for airline being active; fix tests for L7 #718

This commit is contained in:
Nabeel Shahzad 2020-05-23 11:43:29 -04:00
parent 71c09aaeb1
commit c46fc9171c
36 changed files with 954 additions and 627 deletions

View File

@ -74,9 +74,9 @@ reload-db:
tests: test
.PHONY: test
test: phpcs
#php artisan database:create --reset
vendor/bin/phpunit --debug --verbose
test:
@#php artisan database:create --reset
@vendor/bin/phpunit --verbose --debug
.PHONY: phpcs
phpcs:

View File

@ -6,10 +6,10 @@ $factory->define(App\Models\Aircraft::class, function (Faker $faker) {
return [
'id' => null,
'subfleet_id' => function () {
return factory(App\Models\Subfleet::class)->create()->id;
return factory(\App\Models\Subfleet::class)->create()->id;
},
'airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id;
return factory(\App\Models\Airport::class)->create()->id;
},
'iata' => $faker->unique()->text(5),
'icao' => $faker->unique()->text(5),

View File

@ -8,19 +8,19 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) {
return [
'id' => $faker->unique()->numberBetween(10, 10000000),
'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id;
return factory(\App\Models\Airline::class)->create()->id;
},
'flight_number' => $faker->unique()->numberBetween(10, 1000000),
'route_code' => $faker->randomElement(['', $faker->text(5)]),
'route_leg' => $faker->randomElement(['', $faker->numberBetween(0, 1000)]),
'dpt_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id;
return factory(\App\Models\Airport::class)->create()->id;
},
'arr_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id;
return factory(\App\Models\Airport::class)->create()->id;
},
'alt_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id;
return factory(\App\Models\Airport::class)->create()->id;
},
'distance' => $faker->numberBetween(1, 1000),
'route' => null,

View File

@ -6,7 +6,7 @@ $factory->define(App\Models\JournalTransactions::class, function (Faker $faker)
return [
'transaction_group' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
'journal_id' => function () {
return factory(App\Models\Journal::class)->create()->id;
return factory(\App\Models\Journal::class)->create()->id;
},
'credit' => $faker->numberBetween(100, 10000),
'debit' => $faker->numberBetween(100, 10000),

View File

@ -6,7 +6,7 @@ $factory->define(App\Models\News::class, function (Faker $faker) {
return [
'id' => null,
'user_id' => function () {
return factory(App\Models\User::class)->create()->id;
return factory(\App\Models\User::class)->create()->id;
},
'subject' => $faker->text(),
'body' => $faker->sentence,

View File

@ -10,8 +10,8 @@ use Faker\Generator as Faker;
* Create a new PIREP
*/
$factory->define(App\Models\Pirep::class, function (Faker $faker) {
$airline = factory(App\Models\Airline::class)->create();
$flight = factory(App\Models\Flight::class)->create([
$airline = factory(\App\Models\Airline::class)->create();
$flight = factory(\App\Models\Flight::class)->create([
'airline_id' => $airline->id,
]);
@ -21,10 +21,10 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) {
return $airline->id;
},
'user_id' => function () {
return factory(App\Models\User::class)->create()->id;
return factory(\App\Models\User::class)->create()->id;
},
'aircraft_id' => function () {
return factory(App\Models\Aircraft::class)->create()->id;
return factory(\App\Models\Aircraft::class)->create()->id;
},
'flight_id' => function () use ($flight) {
return $flight->id;

View File

@ -6,7 +6,7 @@ $factory->define(App\Models\Subfleet::class, function (Faker $faker) {
return [
'id' => null,
'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id;
return factory(\App\Models\Airline::class)->create()->id;
},
'name' => $faker->unique()->text(50),
'type' => $faker->unique()->text(7),

View File

@ -14,7 +14,7 @@ $factory->define(App\Models\User::class, function (Faker $faker) {
'password' => $password ?: $password = Hash::make('secret'),
'api_key' => $faker->sha1,
'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id;
return factory(\App\Models\Airline::class)->create()->id;
},
'rank_id' => 1,
'flights' => $faker->numberBetween(0, 1000),

View File

@ -12,3 +12,11 @@ airlines:
active: 1
created_at: now
updated_at: now
- id: 2
icao: XXX
iata: XX
name: inactive airline
country: us
active: 0
created_at: now
updated_at: now

View File

@ -6,8 +6,6 @@ use App\Exceptions\Converters\GenericExceptionAbstract;
use App\Exceptions\Converters\SymfonyException;
use App\Exceptions\Converters\ValidationException;
use App\Http\Middleware\SetActiveTheme;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
@ -16,7 +14,6 @@ use Illuminate\Http\Request;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException as IlluminateValidationException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;

View File

@ -78,29 +78,32 @@ class FlightController extends Controller
*/
public function search(Request $request)
{
/** @var \App\Models\User $user */
$user = Auth::user();
$where = [
'active' => true,
'visible' => true,
];
// Allow the option to bypass some of these restrictions for the searches
if (!$request->filled('ignore_restrictions')
|| $request->get('ignore_restrictions') === '0'
) {
if (!$request->filled('ignore_restrictions') || $request->get('ignore_restrictions') === '0') {
if (setting('pilots.restrict_to_company')) {
$where['airline_id'] = Auth::user()->airline_id;
$where['airline_id'] = $user->airline_id;
}
if (setting('pilots.only_flights_from_current')) {
$where['dpt_airport_id'] = Auth::user()->curr_airport_id;
$where['dpt_airport_id'] = $user->curr_airport_id;
}
}
try {
$this->flightRepo->resetCriteria();
$this->flightRepo->searchCriteria($request);
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where, [
'airline' => ['active' => true],
]));
$this->flightRepo->pushCriteria(new RequestCriteria($request));
$flights = $this->flightRepo

View File

@ -75,8 +75,9 @@ class FlightController extends Controller
public function search(Request $request)
{
$where = [
'active' => true,
'visible' => true,
'active' => true,
'visible' => true,
'airlines.active' => true,
];
if (setting('pilots.restrict_to_company')) {

View File

@ -27,14 +27,19 @@ class AirlineRepository extends Repository implements CacheableInterface
/**
* Return the list of airline formatted for a select box
*
* @param mixed $add_blank
* @param bool $add_blank
* @param bool $only_active
*
* @return array
*/
public function selectBoxList($add_blank = false): array
public function selectBoxList($add_blank = false, $only_active = true): array
{
$retval = [];
$items = $this->all();
$where = [
'active' => $only_active,
];
$items = $this->findWhere($where);
if ($add_blank) {
$retval[''] = '';

View File

@ -69,7 +69,7 @@
"friendsofphp/php-cs-fixer": "^2.16",
"mockery/mockery": "0.9.*",
"nunomaduro/collision": "^4.0",
"phpunit/phpunit": "~8.3",
"phpunit/phpunit": "~9.0",
"squizlabs/php_codesniffer": "3.*",
"sempro/phpunit-pretty-print": "^1.2"
},
@ -88,10 +88,7 @@
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
},
"classmap": [
"tests/TestCase.php"
]
}
},
"extra": {
"installer-types": ["phpvms-module"],

823
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,8 +7,7 @@
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
beStrictAboutOutputDuringTests="false"
beStrictAboutTestsThatDoNotTestAnything="false"
printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinter">
beStrictAboutTestsThatDoNotTestAnything="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
@ -34,11 +33,14 @@
<server name="APP_KEY" value="base64:ve66Z5Kt/zTN3p++0zOPu854PHfZkwJE5VuoFAlzHtI="/>
<server name="APP_DEBUG" value="true"/>
<server name="APP_LOG_LEVEL" value="error"/>
<server name="DB_CONNECTION" value="memory"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="QUEUE_DRIVER" value="sync"/>
<server name="DB_CONNECTION" value="memory"/>
<server name="DB_PREFIX" value="vmstest_"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_DRIVER" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
<server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php"/>
<server name="APP_SERVICES_CACHE" value="bootstrap/cache/services.phpunit.php"/>
<server name="APP_PACKAGES_CACHE" value="bootstrap/cache/packages.phpunit.php"/>

View File

@ -1,11 +1,24 @@
<?php
namespace Tests;
use App\Exceptions\AircraftNotAtAirport;
use App\Exceptions\UserNotAtAirport;
use App\Models\Acars;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus;
use App\Models\Fare;
use App\Models\Navdata;
use App\Models\PirepFare;
use App\Models\PirepFieldValue;
use App\Models\User;
use App\Repositories\SettingRepository;
use App\Support\Utils;
use function count;
use function random_int;
/**
* Test API calls and authentication, etc
@ -43,7 +56,7 @@ class AcarsTest extends TestCase
$addtl_fields
);
$this->assertCount(\count($route), $points);
$this->assertCount(count($route), $points);
foreach ($route as $idx => $point) {
$this->assertHasKeys($points[$idx], $fields);
foreach ($fields as $f) {
@ -69,11 +82,11 @@ class AcarsTest extends TestCase
*/
public function testPrefileErrors()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create();
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
$aircraft = factory(Aircraft::class)->create();
/**
* INVALID AIRLINE_ID FIELD
@ -96,10 +109,10 @@ class AcarsTest extends TestCase
public function testBlankAirport()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create();
$airline = factory(Airline::class)->create();
$aircraft = factory(Aircraft::class)->create();
/**
* INVALID AIRLINE_ID FIELD
@ -134,13 +147,13 @@ class AcarsTest extends TestCase
$this->settingsRepo->store('pilots.only_flights_from_current', true);
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'curr_airport_id' => 'KJFK',
]);
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create();
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
$aircraft = factory(Aircraft::class)->create();
/**
* INVALID AIRLINE_ID FIELD
@ -161,7 +174,7 @@ class AcarsTest extends TestCase
$response = $this->post($uri, $pirep);
$response->assertStatus(400);
$body = $response->json();
$this->assertEquals(\App\Exceptions\UserNotAtAirport::MESSAGE, $body['error']['message']);
$this->assertEquals(UserNotAtAirport::MESSAGE, $body['error']['message']);
}
/**
@ -173,13 +186,13 @@ class AcarsTest extends TestCase
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'curr_airport_id' => 'KJFK',
]);
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create([
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
$aircraft = factory(Aircraft::class)->create([
'airport_id' => 'KAUS',
]);
@ -202,7 +215,7 @@ class AcarsTest extends TestCase
$response = $this->post($uri, $pirep);
$response->assertStatus(400);
$body = $response->json();
$this->assertEquals(\App\Exceptions\AircraftNotAtAirport::MESSAGE, $body['error']['message']);
$this->assertEquals(AircraftNotAtAirport::MESSAGE, $body['error']['message']);
}
/**
@ -212,16 +225,16 @@ class AcarsTest extends TestCase
{
$subfleet = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$fare = factory(App\Models\Fare::class)->create();
$fare = factory(Fare::class)->create();
$this->user = factory(App\Models\User::class)->create(
$this->user = factory(User::class)->create(
[
'rank_id' => $rank->id,
]
);
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
$aircraft = $subfleet['aircraft']->random();
$uri = '/api/pireps/prefile';
@ -312,12 +325,12 @@ class AcarsTest extends TestCase
$subfleet = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'rank_id' => $rank->id,
]);
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
$aircraft = $subfleet['aircraft']->random();
$uri = '/api/pireps/prefile';
@ -361,14 +374,14 @@ class AcarsTest extends TestCase
$subfleet = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create(
$this->user = factory(User::class)->create(
[
'rank_id' => $rank->id,
]
);
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
$aircraft = $subfleet['aircraft']->random();
$uri = '/api/pireps/prefile';
@ -438,7 +451,7 @@ class AcarsTest extends TestCase
$response->assertStatus(400);
// Post an ACARS update
$acars = factory(App\Models\Acars::class)->make(['pirep_id' => $pirep_id])->toArray();
$acars = factory(Acars::class)->make(['pirep_id' => $pirep_id])->toArray();
$acars = $this->transformData($acars);
@ -531,12 +544,12 @@ class AcarsTest extends TestCase
$subfleet = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'rank_id' => $rank->id,
]);
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
$aircraft = $subfleet['aircraft']->random();
$uri = '/api/pireps/prefile';
@ -581,8 +594,8 @@ class AcarsTest extends TestCase
{
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', true);
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
// Add subfleets and aircraft, but also add another set of subfleets
$subfleetA = $this->createSubfleetWithAircraft(1);
@ -592,7 +605,7 @@ class AcarsTest extends TestCase
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create(
$this->user = factory(User::class)->create(
[
'rank_id' => $rank->id,
]
@ -627,8 +640,8 @@ class AcarsTest extends TestCase
{
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$airport = factory(App\Models\Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create();
$airport = factory(Airport::class)->create();
$airline = factory(Airline::class)->create();
// Add subfleets and aircraft, but also add another set of subfleets
$subfleetA = $this->createSubfleetWithAircraft(1);
@ -638,7 +651,7 @@ class AcarsTest extends TestCase
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create(
$this->user = factory(User::class)->create(
[
'rank_id' => $rank->id,
]
@ -679,8 +692,8 @@ class AcarsTest extends TestCase
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
// Post an ACARS update
$acars_count = \random_int(5, 10);
$acars = factory(App\Models\Acars::class, $acars_count)->make(['id' => ''])
$acars_count = random_int(5, 10);
$acars = factory(Acars::class, $acars_count)->make(['id' => ''])
->map(function ($point) {
$point['id'] = Utils::generateNewId();
return $point;
@ -701,7 +714,7 @@ class AcarsTest extends TestCase
public function testNonExistentPirepGet()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$uri = '/api/pireps/DOESNTEXIST/acars';
$response = $this->get($uri);
@ -710,10 +723,10 @@ class AcarsTest extends TestCase
public function testNonExistentPirepStore()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$uri = '/api/pireps/DOESNTEXIST/acars/position';
$acars = factory(App\Models\Acars::class)->make()->toArray();
$acars = factory(Acars::class)->make()->toArray();
$response = $this->post($uri, $acars);
$response->assertStatus(404);
}
@ -728,7 +741,7 @@ class AcarsTest extends TestCase
$dt = date('c');
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
$acars = factory(App\Models\Acars::class)->make([
$acars = factory(Acars::class)->make([
'sim_time' => $dt,
])->toArray();
@ -777,7 +790,7 @@ class AcarsTest extends TestCase
$response = $this->post($uri, $pirep);
$pirep_id = $response->json()['data']['id'];
$acars = factory(App\Models\Acars::class)->make();
$acars = factory(Acars::class)->make();
$post_log = [
'logs' => [
['log' => $acars->log],
@ -791,7 +804,7 @@ class AcarsTest extends TestCase
$this->assertEquals(1, $body['count']);
$acars = factory(App\Models\Acars::class)->make();
$acars = factory(Acars::class)->make();
$post_log = [
'events' => [
['event' => $acars->log],
@ -816,9 +829,9 @@ class AcarsTest extends TestCase
$order = 1;
$post_route = [];
$route_count = \random_int(2, 10);
$route_count = random_int(2, 10);
$route = factory(App\Models\Navdata::class, $route_count)->create();
$route = factory(Navdata::class, $route_count)->create();
foreach ($route as $position) {
$post_route[] = [
'order' => $order,

View File

@ -1,5 +1,7 @@
<?php
namespace Tests;
use App\Services\AirlineService;
class AirlineTest extends TestCase
@ -17,7 +19,7 @@ class AirlineTest extends TestCase
public function testAddAirline()
{
$attrs = factory(App\Models\Airline::class)->make([
$attrs = factory(\App\Models\Airline::class)->make([
'iata' => '',
])->toArray();
@ -25,7 +27,7 @@ class AirlineTest extends TestCase
$this->assertNotNull($airline);
// Add another airline, also blank IATA
$attrs = factory(App\Models\Airline::class)->make([
$attrs = factory(\App\Models\Airline::class)->make([
'iata' => '',
])->toArray();
$airline = $this->airlineSvc->createAirline($attrs);
@ -37,8 +39,8 @@ class AirlineTest extends TestCase
*/
public function testDeleteAirlineWithFlight()
{
$airline = factory(App\Models\Airline::class)->create();
factory(App\Models\Flight::class)->create([
$airline = factory(\App\Models\Airline::class)->create();
factory(\App\Models\Flight::class)->create([
'airline_id' => $airline->id,
]);
@ -50,8 +52,8 @@ class AirlineTest extends TestCase
*/
public function testDeleteAirlineWithPirep()
{
$airline = factory(App\Models\Airline::class)->create();
factory(App\Models\Pirep::class)->create([
$airline = factory(\App\Models\Airline::class)->create();
factory(\App\Models\Pirep::class)->create([
'airline_id' => $airline->id,
]);

View File

@ -1,8 +1,19 @@
<?php
namespace Tests;
//use Swagger\Serializer;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\UserState;
use App\Models\Fare;
use App\Models\News;
use App\Models\Subfleet;
use App\Models\User;
use App\Services\FareService;
use Exception;
use function random_int;
/**
* Test API calls and authentication, etc
@ -64,11 +75,11 @@ class ApiTest extends TestCase
*/
public function testGetNews(): void
{
factory(App\Models\News::class)->create();
factory(News::class)->create();
$response = $this->get('/api/news')->json();
$this->assertCount(1, $response['data']);
$this->assertTrue(array_key_exists('user', $response['data'][0]));
$this->assertArrayHasKey('user', $response['data'][0]);
}
/**
@ -76,12 +87,12 @@ class ApiTest extends TestCase
*/
public function testGetAirlines()
{
$size = \random_int(5, 10);
$this->user = factory(App\Models\User::class)->create([
$size = random_int(5, 10);
$this->user = factory(User::class)->create([
'airline_id' => 0,
]);
$airlines = factory(App\Models\Airline::class, $size)->create();
$airlines = factory(Airline::class, $size)->create();
$res = $this->get('/api/airlines');
$this->assertTrue($res->isOk());
@ -96,12 +107,12 @@ class ApiTest extends TestCase
*/
public function testPagination()
{
$size = \random_int(5, 10);
$this->user = factory(App\Models\User::class)->create([
$size = random_int(5, 10);
$this->user = factory(User::class)->create([
'airline_id' => 0,
]);
factory(App\Models\Airline::class, $size)->create();
factory(Airline::class, $size)->create();
/*
* Page 0 and page 1 should return the same thing
@ -142,8 +153,8 @@ class ApiTest extends TestCase
*/
public function testAirportRequest()
{
$this->user = factory(App\Models\User::class)->create();
$airport = factory(App\Models\Airport::class)->create();
$this->user = factory(User::class)->create();
$airport = factory(Airport::class)->create();
$response = $this->get('/api/airports/'.$airport->icao);
@ -158,8 +169,8 @@ class ApiTest extends TestCase
*/
public function testGetAllAirports()
{
$this->user = factory(App\Models\User::class)->create();
factory(App\Models\Airport::class, 70)->create();
$this->user = factory(User::class)->create();
factory(Airport::class, 70)->create();
$response = $this->get('/api/airports/')
->assertStatus(200);
@ -170,9 +181,9 @@ class ApiTest extends TestCase
public function testGetAllAirportsHubs()
{
$this->user = factory(App\Models\User::class)->create();
factory(App\Models\Airport::class, 10)->create();
factory(App\Models\Airport::class)->create(['hub' => 1]);
$this->user = factory(User::class)->create();
factory(Airport::class, 10)->create();
factory(Airport::class)->create(['hub' => 1]);
$this->get('/api/airports/hubs')
->assertStatus(200)
@ -186,23 +197,23 @@ class ApiTest extends TestCase
*/
public function testGetSubfleets()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$subfleetA = factory(App\Models\Subfleet::class)->create([
$subfleetA = factory(Subfleet::class)->create([
'airline_id' => $this->user->airline_id,
]);
$subfleetB = factory(App\Models\Subfleet::class)->create([
$subfleetB = factory(Subfleet::class)->create([
'airline_id' => $this->user->airline_id,
]);
$subfleetA_size = \random_int(2, 10);
$subfleetB_size = \random_int(2, 10);
factory(App\Models\Aircraft::class, $subfleetA_size)->create([
$subfleetA_size = random_int(2, 10);
$subfleetB_size = random_int(2, 10);
factory(Aircraft::class, $subfleetA_size)->create([
'subfleet_id' => $subfleetA->id,
]);
factory(App\Models\Aircraft::class, $subfleetB_size)->create([
factory(Aircraft::class, $subfleetB_size)->create([
'subfleet_id' => $subfleetB->id,
]);
@ -226,18 +237,18 @@ class ApiTest extends TestCase
*/
public function testGetAircraft()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$fare_svc = app(FareService::class);
$subfleet = factory(App\Models\Subfleet::class)->create([
$subfleet = factory(Subfleet::class)->create([
'airline_id' => $this->user->airline_id,
]);
$fare = factory(App\Models\Fare::class)->create();
$fare = factory(Fare::class)->create();
$fare_svc->setForSubfleet($subfleet, $fare);
$aircraft = factory(App\Models\Aircraft::class)->create([
$aircraft = factory(Aircraft::class)->create([
'subfleet_id' => $subfleet->id,
]);
@ -259,14 +270,14 @@ class ApiTest extends TestCase
public function testGetAllSettings()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$res = $this->get('/api/settings')->assertStatus(200);
$settings = $res->json();
}
public function testGetUser()
{
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'avatar' => '/assets/avatar.jpg',
]);
@ -277,7 +288,7 @@ class ApiTest extends TestCase
// Should go to gravatar
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$res = $this->get('/api/user')->assertStatus(200);
$user = $res->json('data');

View File

@ -1,8 +1,14 @@
<?php
namespace Tests;
use App\Models\Award;
use App\Models\Pirep;
use App\Models\User;
use App\Models\UserAward;
use App\Services\AwardService;
use App\Services\PirepService;
use Modules\Awards\Awards\PilotFlightAwards;
class AwardsTest extends TestCase
{
@ -35,16 +41,16 @@ class AwardsTest extends TestCase
public function testAwardsGiven()
{
// Create one award that's given out with one flight
$award = factory(App\Models\Award::class)->create([
'ref_model' => Modules\Awards\Awards\PilotFlightAwards::class,
$award = factory(Award::class)->create([
'ref_model' => PilotFlightAwards::class,
'ref_model_params' => 1,
]);
$user = factory(App\Models\User::class)->create([
$user = factory(User::class)->create([
'flights' => 0,
]);
$pirep = factory(App\Models\Pirep::class)->create([
$pirep = factory(Pirep::class)->create([
'airline_id' => $user->airline->id,
'user_id' => $user->id,
]);

View File

@ -1,8 +1,11 @@
<?php
namespace Tests;
use App\Exceptions\BidExistsForFlight;
use App\Models\Bid;
use App\Models\Flight;
use App\Models\Subfleet;
use App\Models\User;
use App\Repositories\SettingRepository;
use App\Services\BidService;
@ -26,12 +29,12 @@ class BidTest extends TestCase
public function addFlight($user)
{
$flight = factory(App\Models\Flight::class)->create([
$flight = factory(Flight::class)->create([
'airline_id' => $user->airline_id,
]);
$flight->subfleets()->syncWithoutDetaching([
factory(App\Models\Subfleet::class)->create([
factory(Subfleet::class)->create([
'airline_id' => $user->airline_id,
])->id,
]);

View File

@ -27,6 +27,7 @@ class Bootstrap implements BeforeFirstTestHook, AfterLastTestHook
'config:cache',
'event:cache',
];
foreach ($commands as $command) {
$console->call($command);
}

View File

@ -1,9 +1,19 @@
<?php
namespace Tests;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\ExpenseType;
use App\Models\Enums\FlightType;
use App\Models\Enums\PirepSource;
use App\Models\Expense;
use App\Models\Fare;
use App\Models\Flight;
use App\Models\Journal;
use App\Models\Pirep;
use App\Models\Subfleet;
use App\Models\User;
use App\Repositories\ExpenseRepository;
use App\Repositories\JournalRepository;
use App\Services\FareService;
@ -12,6 +22,7 @@ use App\Services\FleetService;
use App\Services\PirepService;
use App\Support\Math;
use App\Support\Money;
use Exception;
class FinanceTest extends TestCase
{
@ -60,27 +71,29 @@ class FinanceTest extends TestCase
$this->fleetSvc->addSubfleetToRank($subfleet['subfleet'], $rank);
$dpt_apt = factory(App\Models\Airport::class)->create([
$dpt_apt = factory(Airport::class)->create([
'ground_handling_cost' => 10,
'fuel_jeta_cost' => 10,
]);
$arr_apt = factory(App\Models\Airport::class)->create([
$arr_apt = factory(Airport::class)->create([
'ground_handling_cost' => 10,
'fuel_jeta_cost' => 10,
]);
$user = factory(App\Models\User::class)->create([
/** @var \App\Models\User $user */
$user = factory(User::class)->create([
'rank_id' => $rank->id,
]);
$flight = factory(App\Models\Flight::class)->create([
/** @var \App\Models\Flight $flight */
$flight = factory(Flight::class)->create([
'airline_id' => $user->airline_id,
'dpt_airport_id' => $dpt_apt->icao,
'arr_airport_id' => $arr_apt->icao,
]);
$pirep = factory(App\Models\Pirep::class)->create([
$pirep = factory(Pirep::class)->create([
'flight_number' => $flight->flight_number,
'flight_type' => FlightType::SCHED_PAX,
'route_code' => $flight->route_code,
@ -101,7 +114,7 @@ class FinanceTest extends TestCase
* Add fares to the subfleet, and then add the fares
* to the PIREP when it's saved, and set the capacity
*/
$fares = factory(App\Models\Fare::class, 3)->create([
$fares = factory(Fare::class, 3)->create([
'price' => 100,
'cost' => 50,
'capacity' => 10,
@ -112,13 +125,13 @@ class FinanceTest extends TestCase
}
// Add an expense
factory(App\Models\Expense::class)->create([
factory(Expense::class)->create([
'airline_id' => null,
'amount' => 100,
]);
// Add a subfleet expense
factory(App\Models\Expense::class)->create([
factory(Expense::class)->create([
'ref_model' => Subfleet::class,
'ref_model_id' => $subfleet['subfleet']->id,
'amount' => 200,
@ -131,8 +144,8 @@ class FinanceTest extends TestCase
public function testFlightFaresNoOverride()
{
$flight = factory(App\Models\Flight::class)->create();
$fare = factory(App\Models\Fare::class)->create();
$flight = factory(Flight::class)->create();
$fare = factory(Fare::class)->create();
$this->fareSvc->setForFlight($flight, $fare);
$subfleet_fares = $this->fareSvc->getForFlight($flight);
@ -165,8 +178,8 @@ class FinanceTest extends TestCase
*/
public function testFlightFareOverrideAsPercent()
{
$flight = factory(App\Models\Flight::class)->create();
$fare = factory(App\Models\Fare::class)->create();
$flight = factory(Flight::class)->create();
$fare = factory(Fare::class)->create();
$percent_incr = '20%';
$percent_decr = '-20%';
@ -192,8 +205,8 @@ class FinanceTest extends TestCase
public function testSubfleetFaresNoOverride()
{
$subfleet = factory(App\Models\Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create();
$subfleet = factory(Subfleet::class)->create();
$fare = factory(Fare::class)->create();
$this->fareSvc->setForSubfleet($subfleet, $fare);
$subfleet_fares = $this->fareSvc->getForSubfleet($subfleet);
@ -223,8 +236,8 @@ class FinanceTest extends TestCase
public function testSubfleetFaresOverride()
{
$subfleet = factory(App\Models\Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create();
$subfleet = factory(Subfleet::class)->create();
$fare = factory(Fare::class)->create();
$this->fareSvc->setForSubfleet($subfleet, $fare, [
'price' => 50, 'capacity' => 400,
@ -260,8 +273,8 @@ class FinanceTest extends TestCase
*/
public function testSubfleetFareOverrideAsPercent()
{
$subfleet = factory(App\Models\Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create();
$subfleet = factory(Subfleet::class)->create();
$fare = factory(Fare::class)->create();
$percent_incr = '20%';
$percent_decr = '-20%';
@ -291,9 +304,9 @@ class FinanceTest extends TestCase
*/
public function testGetFaresWithOverrides()
{
$flight = factory(App\Models\Flight::class)->create();
$subfleet = factory(App\Models\Subfleet::class)->create();
[$fare1, $fare2, $fare3, $fare4] = factory(App\Models\Fare::class, 4)->create();
$flight = factory(Flight::class)->create();
$subfleet = factory(Subfleet::class)->create();
[$fare1, $fare2, $fare3, $fare4] = factory(Fare::class, 4)->create();
// add to the subfleet, and just override one of them
$this->fareSvc->setForSubfleet($subfleet, $fare1);
@ -345,8 +358,8 @@ class FinanceTest extends TestCase
public function testGetFaresNoFlightOverrides()
{
$subfleet = factory(App\Models\Subfleet::class)->create();
[$fare1, $fare2, $fare3] = factory(App\Models\Fare::class, 3)->create();
$subfleet = factory(Subfleet::class)->create();
[$fare1, $fare2, $fare3] = factory(Fare::class, 3)->create();
// add to the subfleet, and just override one of them
$this->fareSvc->setForSubfleet($subfleet, $fare1);
@ -393,11 +406,11 @@ class FinanceTest extends TestCase
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$this->fleetSvc->addSubfleetToRank($subfleet['subfleet'], $rank);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'rank_id' => $rank->id,
]);
$pirep = factory(App\Models\Pirep::class)->create([
$pirep = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS,
@ -420,11 +433,11 @@ class FinanceTest extends TestCase
'acars_pay' => $acars_pay_rate,
]);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'rank_id' => $rank->id,
]);
$pirep_acars = factory(App\Models\Pirep::class)->create([
$pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS,
@ -444,7 +457,7 @@ class FinanceTest extends TestCase
'manual_pay' => $manual_pay_rate,
]);
$pirep_manual = factory(App\Models\Pirep::class)->create([
$pirep_manual = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::MANUAL,
@ -471,11 +484,11 @@ class FinanceTest extends TestCase
'acars_pay' => $acars_pay_rate,
]);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'rank_id' => $rank->id,
]);
$pirep_acars = factory(App\Models\Pirep::class)->create([
$pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS,
@ -485,7 +498,7 @@ class FinanceTest extends TestCase
$payment = $this->financeSvc->getPilotPay($pirep_acars);
$this->assertEquals(100, $payment->getValue());
$pirep_acars = factory(App\Models\Pirep::class)->create([
$pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS,
@ -506,16 +519,16 @@ class FinanceTest extends TestCase
'acars_pay' => $acars_pay_rate,
]);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'rank_id' => $rank->id,
]);
$flight = factory(App\Models\Flight::class)->create([
$flight = factory(Flight::class)->create([
'airline_id' => $this->user->airline_id,
'pilot_pay' => 1000,
]);
$pirep_acars = factory(App\Models\Pirep::class)->create([
$pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS,
@ -526,7 +539,7 @@ class FinanceTest extends TestCase
$payment = $this->financeSvc->getPilotPay($pirep_acars);
$this->assertEquals(1000, $payment->getValue());
$pirep_acars = factory(App\Models\Pirep::class)->create([
$pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS,
@ -544,8 +557,8 @@ class FinanceTest extends TestCase
{
$journalRepo = app(JournalRepository::class);
$user = factory(App\Models\User::class)->create();
$journal = factory(App\Models\Journal::class)->create();
$user = factory(User::class)->create();
$journal = factory(Journal::class)->create();
$journalRepo->post(
$journal,
@ -624,18 +637,18 @@ class FinanceTest extends TestCase
*/
public function testPirepExpenses()
{
$airline = factory(App\Models\Airline::class)->create();
$airline2 = factory(App\Models\Airline::class)->create();
$airline = factory(Airline::class)->create();
$airline2 = factory(Airline::class)->create();
factory(App\Models\Expense::class)->create([
factory(Expense::class)->create([
'airline_id' => $airline->id,
]);
factory(App\Models\Expense::class)->create([
factory(Expense::class)->create([
'airline_id' => $airline2->id,
]);
factory(App\Models\Expense::class)->create([
factory(Expense::class)->create([
'airline_id' => null,
]);
@ -660,8 +673,8 @@ class FinanceTest extends TestCase
* Test the subfleet class
*/
$subfleet = factory(App\Models\Subfleet::class)->create();
factory(App\Models\Expense::class)->create([
$subfleet = factory(Subfleet::class)->create();
factory(Expense::class)->create([
'airline_id' => null,
'ref_model' => Subfleet::class,
'ref_model_id' => $subfleet->id,
@ -737,7 +750,7 @@ class FinanceTest extends TestCase
$journalRepo = app(JournalRepository::class);
// Add an expense that's only for a cargo flight
factory(App\Models\Expense::class)->create([
factory(Expense::class)->create([
'airline_id' => null,
'amount' => 100,
'flight_type' => FlightType::SCHED_CARGO,
@ -784,7 +797,7 @@ class FinanceTest extends TestCase
}
// Add a new PIREP;
$pirep2 = factory(App\Models\Pirep::class)->create([
$pirep2 = factory(Pirep::class)->create([
'flight_number' => 100,
'flight_type' => FlightType::SCHED_CARGO,
'dpt_airport_id' => $pirep->dpt_airport_id,

View File

@ -1,14 +1,23 @@
<?php
namespace Tests;
use App\Cron\Nightly\SetActiveFlights;
use App\Events\CronNightly;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\Days;
use App\Models\Enums\NavaidType;
use App\Models\Flight;
use App\Models\Navdata;
use App\Models\Subfleet;
use App\Models\User;
use App\Repositories\SettingRepository;
use App\Services\AirportService;
use App\Services\FleetService;
use App\Services\FlightService;
use Carbon\Carbon;
use Exception;
class FlightTest extends TestCase
{
@ -38,10 +47,10 @@ class FlightTest extends TestCase
'airline_id' => $user->airline_id,
], $flight_properties);
$flight = factory(App\Models\Flight::class)->create($opts);
$flight = factory(Flight::class)->create($opts);
$flight->subfleets()->syncWithoutDetaching([
factory(App\Models\Subfleet::class)->create([
factory(Subfleet::class)->create([
'airline_id' => $user->airline_id,
])->id,
]);
@ -59,7 +68,7 @@ class FlightTest extends TestCase
*/
public function addFlightsForSubfleet($subfleet, $num_flights)
{
return factory(App\Models\Flight::class, $num_flights)->create([
return factory(Flight::class, $num_flights)->create([
'airline_id' => $subfleet->airline->id,
])->each(function (Flight $f) use ($subfleet) {
$f->subfleets()->syncWithoutDetaching([
@ -73,7 +82,7 @@ class FlightTest extends TestCase
*/
public function testDuplicateFlight()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user);
// first flight shouldn't be a duplicate
@ -89,7 +98,7 @@ class FlightTest extends TestCase
$this->assertTrue($this->flightSvc->isFlightDuplicate($flight_dupe));
// same flight but diff airline shouldn't be a dupe
$new_airline = factory(App\Models\Airline::class)->create();
$new_airline = factory(Airline::class)->create();
$flight_dupe = new Flight([
'airline_id' => $new_airline->airline_id,
'flight_number' => $flight->flight_number,
@ -100,7 +109,7 @@ class FlightTest extends TestCase
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_dupe));
// add another flight with a code
$flight_leg = factory(App\Models\Flight::class)->create([
$flight_leg = factory(Flight::class)->create([
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => 'A',
@ -109,7 +118,7 @@ class FlightTest extends TestCase
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_leg));
// Add both a route and leg
$flight_leg = factory(App\Models\Flight::class)->create([
$flight_leg = factory(Flight::class)->create([
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => 'A',
@ -121,7 +130,7 @@ class FlightTest extends TestCase
public function testGetFlight()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user, [
'load_factor' => '',
'load_factor_variance' => '',
@ -148,7 +157,7 @@ class FlightTest extends TestCase
*/
public function testSearchFlight()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user);
// search specifically for a flight ID
@ -157,6 +166,29 @@ class FlightTest extends TestCase
$req->assertStatus(200);
}
public function testSearchFlightInactiveAirline()
{
/** @var \App\Models\Airline $airline_inactive */
$airline_inactive = factory(Airline::class)->create(['active' => 0]);
/** @var \App\Models\Airline $airline_active */
$airline_active = factory(Airline::class)->create(['active' => 1]);
$this->user = factory(User::class)->create([
'airline_id' => $airline_inactive->id,
]);
$this->addFlight($this->user, ['airline_id' => $airline_inactive->id]);
$this->addFlight($this->user, ['airline_id' => $airline_active->id]);
// search specifically for a flight ID
$req = $this->get('/api/flights/search?ignore_restrictions=1');
$req->assertStatus(200);
$body = $req->json('data');
$this->assertEquals(1, count($body));
$this->assertEquals($airline_active->id, $body[0]['airline_id']);
}
/**
* Get the flight's route
*
@ -164,11 +196,11 @@ class FlightTest extends TestCase
*/
public function testFlightRoute()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user);
$route_count = random_int(4, 6);
$route = factory(App\Models\Navdata::class, $route_count)->create();
$route = factory(Navdata::class, $route_count)->create();
$route_text = implode(' ', $route->pluck('id')->toArray());
$flight->route = $route_text;
@ -198,8 +230,8 @@ class FlightTest extends TestCase
*/
public function testFindAllFlights()
{
$this->user = factory(App\Models\User::class)->create();
factory(App\Models\Flight::class, 20)->create([
$this->user = factory(User::class)->create();
factory(Flight::class, 20)->create([
'airline_id' => $this->user->airline_id,
]);
@ -217,12 +249,12 @@ class FlightTest extends TestCase
*/
public function testSearchFlightBySubfleet()
{
$airline = factory(App\Models\Airline::class)->create();
$subfleetA = factory(App\Models\Subfleet::class)->create(['airline_id' => $airline->id]);
$subfleetB = factory(App\Models\Subfleet::class)->create(['airline_id' => $airline->id]);
$airline = factory(Airline::class)->create();
$subfleetA = factory(Subfleet::class)->create(['airline_id' => $airline->id]);
$subfleetB = factory(Subfleet::class)->create(['airline_id' => $airline->id]);
$rank = $this->createRank(0, [$subfleetB->id]);
$this->user = factory(App\Models\User::class)->create([
$this->user = factory(User::class)->create([
'airline_id' => $airline->id,
'rank_id' => $rank->id,
]);
@ -250,12 +282,12 @@ class FlightTest extends TestCase
*/
public function testFindDaysOfWeek(): void
{
$this->user = factory(App\Models\User::class)->create();
factory(App\Models\Flight::class, 20)->create([
$this->user = factory(User::class)->create();
factory(Flight::class, 20)->create([
'airline_id' => $this->user->airline_id,
]);
$saved_flight = factory(App\Models\Flight::class)->create([
$saved_flight = factory(Flight::class)->create([
'airline_id' => $this->user->airline_id,
'days' => Days::getDaysMask([
Days::SUNDAY,
@ -283,7 +315,7 @@ class FlightTest extends TestCase
*/
public function testDayOfWeekActive(): void
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
// Set it to Monday or Tuesday, depending on what today is
if (date('N') === '1') { // today is a monday
@ -292,8 +324,8 @@ class FlightTest extends TestCase
$days = Days::getDaysMask([Days::MONDAY]);
}
factory(App\Models\Flight::class, 5)->create();
$flight = factory(App\Models\Flight::class)->create([
factory(Flight::class, 5)->create();
$flight = factory(Flight::class)->create([
'days' => $days,
]);
@ -331,17 +363,17 @@ class FlightTest extends TestCase
public function testStartEndDate(): void
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
factory(App\Models\Flight::class, 5)->create();
$flight = factory(App\Models\Flight::class)->create([
'start_date' => Carbon\Carbon::now('UTC')->subDays(1),
'end_date' => Carbon\Carbon::now('UTC')->addDays(1),
factory(Flight::class, 5)->create();
$flight = factory(Flight::class)->create([
'start_date' => Carbon::now('UTC')->subDays(1),
'end_date' => Carbon::now('UTC')->addDays(1),
]);
$flight_not_active = factory(App\Models\Flight::class)->create([
'start_date' => Carbon\Carbon::now('UTC')->subDays(10),
'end_date' => Carbon\Carbon::now('UTC')->subDays(2),
$flight_not_active = factory(Flight::class)->create([
'start_date' => Carbon::now('UTC')->subDays(10),
'end_date' => Carbon::now('UTC')->subDays(2),
]);
// Run the event that will enable/disable flights
@ -360,7 +392,7 @@ class FlightTest extends TestCase
public function testStartEndDateDayOfWeek(): void
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
// Set it to Monday or Tuesday, depending on what today is
if (date('N') === '1') { // today is a monday
@ -369,17 +401,17 @@ class FlightTest extends TestCase
$days = Days::getDaysMask([Days::MONDAY]);
}
factory(App\Models\Flight::class, 5)->create();
$flight = factory(App\Models\Flight::class)->create([
'start_date' => Carbon\Carbon::now('UTC')->subDays(1),
'end_date' => Carbon\Carbon::now('UTC')->addDays(1),
factory(Flight::class, 5)->create();
$flight = factory(Flight::class)->create([
'start_date' => Carbon::now('UTC')->subDays(1),
'end_date' => Carbon::now('UTC')->addDays(1),
'days' => Days::$isoDayMap[date('N')],
]);
// Not active because of days of week not today
$flight_not_active = factory(App\Models\Flight::class)->create([
'start_date' => Carbon\Carbon::now('UTC')->subDays(1),
'end_date' => Carbon\Carbon::now('UTC')->addDays(1),
$flight_not_active = factory(Flight::class)->create([
'start_date' => Carbon::now('UTC')->subDays(1),
'end_date' => Carbon::now('UTC')->addDays(1),
'days' => $days,
]);
@ -399,8 +431,8 @@ class FlightTest extends TestCase
public function testFlightSearchApi()
{
$this->user = factory(App\Models\User::class)->create();
$flights = factory(App\Models\Flight::class, 10)->create([
$this->user = factory(User::class)->create();
$flights = factory(Flight::class, 10)->create([
'airline_id' => $this->user->airline_id,
]);
@ -415,12 +447,12 @@ class FlightTest extends TestCase
public function testFlightSearchApiDepartureAirport()
{
$this->user = factory(App\Models\User::class)->create();
factory(App\Models\Flight::class, 10)->create([
$this->user = factory(User::class)->create();
factory(Flight::class, 10)->create([
'airline_id' => $this->user->airline_id,
]);
$flight = factory(App\Models\Flight::class)->create([
$flight = factory(Flight::class)->create([
'airline_id' => $this->user->airline_id,
'dpt_airport_id' => 'KAUS',
]);
@ -436,8 +468,8 @@ class FlightTest extends TestCase
public function testFlightSearchApiDistance()
{
$total_flights = 10;
$this->user = factory(App\Models\User::class)->create();
$flights = factory(App\Models\Flight::class, $total_flights)->create([
$this->user = factory(User::class)->create();
$flights = factory(Flight::class, $total_flights)->create([
'airline_id' => $this->user->airline_id,
]);
@ -474,10 +506,10 @@ class FlightTest extends TestCase
public function testAddSubfleet()
{
$subfleet = factory(App\Models\Subfleet::class)->create();
$flight = factory(App\Models\Flight::class)->create();
$subfleet = factory(Subfleet::class)->create();
$flight = factory(Flight::class)->create();
$fleetSvc = app(App\Services\FleetService::class);
$fleetSvc = app(FleetService::class);
$fleetSvc->addSubfleetToFlight($subfleet, $flight);
$flight->refresh();
@ -508,13 +540,13 @@ class FlightTest extends TestCase
public function testAirportDistance()
{
// KJFK
$fromIcao = factory(App\Models\Airport::class)->create([
$fromIcao = factory(Airport::class)->create([
'lat' => 40.6399257,
'lon' => -73.7786950,
]);
// KSFO
$toIcao = factory(App\Models\Airport::class)->create([
$toIcao = factory(Airport::class)->create([
'lat' => 37.6188056,
'lon' => -122.3754167,
]);
@ -531,13 +563,13 @@ class FlightTest extends TestCase
$headers = $this->headers($user);
// KJFK
$fromIcao = factory(App\Models\Airport::class)->create([
$fromIcao = factory(Airport::class)->create([
'lat' => 40.6399257,
'lon' => -73.7786950,
]);
// KSFO
$toIcao = factory(App\Models\Airport::class)->create([
$toIcao = factory(Airport::class)->create([
'lat' => 37.6188056,
'lon' => -122.3754167,
]);

View File

@ -1,5 +1,9 @@
<?php
namespace Tests;
use App\Models\Navdata;
use Exception;
use Illuminate\Foundation\Testing\WithoutMiddleware;
class GeoTest extends TestCase
@ -44,7 +48,7 @@ class GeoTest extends TestCase
$route = [];
$nav_count = random_int(5, 20);
$navpoints = factory(App\Models\Navdata::class, $nav_count)->create();
$navpoints = factory(Navdata::class, $nav_count)->create();
foreach ($navpoints as $point) {
$route[] = $point->id;
}

View File

@ -1,7 +1,10 @@
<?php
namespace Tests;
use App\Contracts\ImportExport;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\AircraftStatus;
use App\Models\Enums\Days;
@ -18,6 +21,7 @@ use App\Services\ImportExport\AircraftExporter;
use App\Services\ImportExport\AirportExporter;
use App\Services\ImportExport\FlightExporter;
use App\Services\ImportService;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\ValidationException;
class ImporterTest extends TestCase
@ -50,18 +54,18 @@ class ImporterTest extends TestCase
'name' => 'phpVMS Airlines',
];
$airline = factory(App\Models\Airline::class)->create($al);
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']);
$airline = factory(Airline::class)->create($al);
$subfleet = factory(Subfleet::class)->create(['type' => 'A32X']);
// Add the economy class
$fare_economy = factory(App\Models\Fare::class)->create(['code' => 'Y', 'capacity' => 150]);
$fare_economy = factory(Fare::class)->create(['code' => 'Y', 'capacity' => 150]);
$fare_svc->setForSubfleet($subfleet, $fare_economy);
$fare_business = factory(App\Models\Fare::class)->create(['code' => 'B', 'capacity' => 20]);
$fare_business = factory(Fare::class)->create(['code' => 'B', 'capacity' => 20]);
$fare_svc->setForSubfleet($subfleet, $fare_business);
// Add first class
$fare_first = factory(App\Models\Fare::class)->create(['code' => 'F', 'capacity' => 10]);
$fare_first = factory(Fare::class)->create(['code' => 'F', 'capacity' => 10]);
$fare_svc->setForSubfleet($subfleet, $fare_first);
return [$airline, $subfleet];
@ -247,7 +251,7 @@ class ImporterTest extends TestCase
*/
public function testAircraftExporter(): void
{
$aircraft = factory(App\Models\Aircraft::class)->create();
$aircraft = factory(Aircraft::class)->create();
$exporter = new AircraftExporter();
$exported = $exporter->export($aircraft);
@ -273,7 +277,7 @@ class ImporterTest extends TestCase
{
$airport_name = 'Adolfo Suárez MadridBarajas Airport';
$airport = factory(App\Models\Airport::class)->create([
$airport = factory(Airport::class)->create([
'name' => $airport_name,
]);
@ -301,12 +305,12 @@ class ImporterTest extends TestCase
$fareSvc = app(FareService::class);
[$airline, $subfleet] = $this->insertFlightsScaffoldData();
$subfleet2 = factory(App\Models\Subfleet::class)->create(['type' => 'B74X']);
$subfleet2 = factory(Subfleet::class)->create(['type' => 'B74X']);
$fareY = Fare::where('code', 'Y')->first();
$fareF = Fare::where('code', 'F')->first();
$flight = factory(App\Models\Flight::class)->create([
$flight = factory(Flight::class)->create([
'airline_id' => $airline->id,
'flight_type' => 'J',
'days' => Days::getDaysMask([
@ -384,9 +388,9 @@ class ImporterTest extends TestCase
*/
public function testExpenseImporter(): void
{
$airline = factory(App\Models\Airline::class)->create(['icao' => 'VMS']);
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => '744-3X-RB211']);
$aircraft = factory(App\Models\Aircraft::class)->create([
$airline = factory(Airline::class)->create(['icao' => 'VMS']);
$subfleet = factory(Subfleet::class)->create(['type' => '744-3X-RB211']);
$aircraft = factory(Aircraft::class)->create([
'subfleet_id' => $subfleet->id,
'registration' => '001Z',
]);
@ -564,8 +568,8 @@ class ImporterTest extends TestCase
*/
public function testAircraftImporter(): void
{
factory(App\Models\Airline::class)->create();
// $subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']);
factory(Airline::class)->create();
// $subfleet = factory(\App\Models\Subfleet::class)->create(['type' => 'A32X']);
$file_path = base_path('tests/data/aircraft.csv');
$status = $this->importSvc->importAircraft($file_path);
@ -646,9 +650,9 @@ class ImporterTest extends TestCase
*/
public function testSubfleetImporter(): void
{
$fare_economy = factory(App\Models\Fare::class)->create(['code' => 'Y', 'capacity' => 150]);
$fare_business = factory(App\Models\Fare::class)->create(['code' => 'B', 'capacity' => 20]);
$airline = factory(App\Models\Airline::class)->create(['icao' => 'VMS']);
$fare_economy = factory(Fare::class)->create(['code' => 'Y', 'capacity' => 150]);
$fare_business = factory(Fare::class)->create(['code' => 'B', 'capacity' => 20]);
$airline = factory(Airline::class)->create(['icao' => 'VMS']);
$file_path = base_path('tests/data/subfleets.csv');
$status = $this->importSvc->importSubfleets($file_path);

View File

@ -1,5 +1,7 @@
<?php
namespace Tests;
use App\Support\Math;
use App\Support\Units\Distance;

View File

@ -1,5 +1,7 @@
<?php
namespace Tests;
use App\Repositories\SettingRepository;
use App\Services\AirportService;
use App\Support\Metar;
@ -9,6 +11,7 @@ use App\Support\Metar;
*/
class MetarTest extends TestCase
{
/** @var SettingRepository */
private $settingsRepo;
public function setUp(): void

View File

@ -1,11 +1,15 @@
<?php
namespace Tests;
use App\Models\Acars;
use App\Models\Aircraft;
use App\Models\Bid;
use App\Models\Enums\AcarsType;
use App\Models\Enums\PirepState;
use App\Models\Enums\UserState;
use App\Models\Flight;
use App\Models\Navdata;
use App\Models\Pirep;
use App\Models\User;
use App\Notifications\Messages\PirepAccepted;
@ -38,7 +42,7 @@ class PIREPTest extends TestCase
protected function createNewRoute()
{
$route = [];
$navpoints = factory(App\Models\Navdata::class, 5)->create();
$navpoints = factory(Navdata::class, 5)->create();
foreach ($navpoints as $point) {
$route[] = $point->id;
}
@ -65,10 +69,10 @@ class PIREPTest extends TestCase
*/
public function testAddPirep()
{
$user = factory(App\Models\User::class)->create();
$user = factory(User::class)->create();
$route = $this->createNewRoute();
$pirep = factory(App\Models\Pirep::class)->create([
$pirep = factory(Pirep::class)->create([
'user_id' => $user->id,
'route' => implode(' ', $route),
]);
@ -171,18 +175,18 @@ class PIREPTest extends TestCase
public function testGetUserPireps()
{
$this->user = factory(App\Models\User::class)->create();
$pirep_done = factory(App\Models\Pirep::class)->create([
$this->user = factory(User::class)->create();
$pirep_done = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'state' => PirepState::ACCEPTED,
]);
$pirep_in_progress = factory(App\Models\Pirep::class)->create([
$pirep_in_progress = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'state' => PirepState::IN_PROGRESS,
]);
$pirep_cancelled = factory(App\Models\Pirep::class)->create([
$pirep_cancelled = factory(Pirep::class)->create([
'user_id' => $this->user->id,
'state' => PirepState::CANCELLED,
]);
@ -360,7 +364,7 @@ class PIREPTest extends TestCase
*/
public function testDuplicatePireps()
{
$user = factory(App\Models\User::class)->create();
$user = factory(User::class)->create();
$pirep = factory(Pirep::class)->create([
'user_id' => $user->id,
]);
@ -392,7 +396,7 @@ class PIREPTest extends TestCase
$pirep_id = $response->json()['data']['id'];
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
$acars = factory(App\Models\Acars::class)->make()->toArray();
$acars = factory(Acars::class)->make()->toArray();
$response = $this->post($uri, [
'positions' => [$acars],
]);
@ -406,7 +410,7 @@ class PIREPTest extends TestCase
// Should get a 400 when posting an ACARS update
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
$acars = factory(App\Models\Acars::class)->make()->toArray();
$acars = factory(Acars::class)->make()->toArray();
$response = $this->post($uri, $acars);
$response->assertStatus(400);
@ -421,18 +425,18 @@ class PIREPTest extends TestCase
$flightSvc = app(FlightService::class);
$this->settingsRepo->store('pireps.remove_bid_on_accept', true);
$user = factory(App\Models\User::class)->create([
$user = factory(User::class)->create([
'flight_time' => 0,
]);
$flight = factory(App\Models\Flight::class)->create([
$flight = factory(Flight::class)->create([
'route_code' => null,
'route_leg' => null,
]);
$bidSvc->addBid($flight, $user);
$pirep = factory(App\Models\Pirep::class)->create([
$pirep = factory(Pirep::class)->create([
'user_id' => $user->id,
'airline_id' => $flight->airline_id,
'flight_id' => $flight->id,

View File

@ -1,5 +1,7 @@
<?php
namespace Tests;
use App\Events\UserRegistered;
use App\Models\Enums\UserState;
use Illuminate\Support\Facades\Event;
@ -11,7 +13,7 @@ class RegistrationTest extends TestCase
/**
* A basic test example.
*
* @throws Exception
* @throws \Exception
*
* @return void
*/
@ -24,7 +26,7 @@ class RegistrationTest extends TestCase
setting('pilots.auto_accept', true);
$attrs = factory(App\Models\User::class)->make()->toArray();
$attrs = factory(\App\Models\User::class)->make()->toArray();
$attrs['password'] = Hash::make('secret');
$user = $userSvc->createUser($attrs);

View File

@ -1,8 +1,13 @@
<?php
namespace Tests;
use App\Models\Acars;
use App\Models\Enums\AcarsType;
use App\Models\Flight;
use App\Models\Pirep;
use App\Models\SimBrief;
use App\Models\User;
use App\Services\SimBriefService;
use App\Support\Utils;
use Carbon\Carbon;
@ -20,7 +25,7 @@ class SimBriefTest extends TestCase
*/
protected function loadSimBrief($user): SimBrief
{
$flight = factory(App\Models\Flight::class)->create([
$flight = factory(Flight::class)->create([
'id' => self::$simbrief_flight_id,
'dpt_airport_id' => 'OMAA',
'arr_airport_id' => 'OMDB',
@ -42,7 +47,7 @@ class SimBriefTest extends TestCase
*/
public function testReadSimbrief()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$briefing = $this->loadSimBrief($this->user);
$this->assertNotEmpty($briefing->ofp_xml);
@ -81,7 +86,7 @@ class SimBriefTest extends TestCase
*/
public function testApiCalls()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$briefing = $this->loadSimBrief($this->user);
// Check the flight API response
@ -115,7 +120,7 @@ class SimBriefTest extends TestCase
*/
public function testUserBidSimbrief()
{
$this->user = factory(App\Models\User::class)->create();
$this->user = factory(User::class)->create();
$this->loadSimBrief($this->user);
// Find the flight
@ -131,8 +136,8 @@ class SimBriefTest extends TestCase
public function testAttachToPirep()
{
$user = factory(App\Models\User::class)->create();
$pirep = factory(App\Models\Pirep::class)->create([
$user = factory(User::class)->create();
$pirep = factory(Pirep::class)->create([
'user_id' => $user->id,
'dpt_airport_id' => 'OMAA',
'arr_airport_id' => 'OMDB',
@ -167,7 +172,7 @@ class SimBriefTest extends TestCase
*/
public function testClearExpiredBriefs()
{
$user = factory(App\Models\User::class)->create();
$user = factory(User::class)->create();
$sb_ignored = factory(SimBrief::class)->create([
'user_id' => $user->id,
'flight_id' => 'a_flight_id',

View File

@ -1,5 +1,11 @@
<?php
namespace Tests;
use App\Models\Fare;
use App\Models\Subfleet;
use App\Services\FareService;
class SubfleetTest extends TestCase
{
protected $ac_svc;
@ -13,10 +19,10 @@ class SubfleetTest extends TestCase
public function testSubfleetFaresNoOverride()
{
$fare_svc = app('App\Services\FareService');
$fare_svc = app(FareService::class);
$subfleet = factory(App\Models\Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create();
$subfleet = factory(Subfleet::class)->create();
$fare = factory(Fare::class)->create();
$fare_svc->setForSubfleet($subfleet, $fare);
$subfleet_fares = $fare_svc->getForSubfleet($subfleet);
@ -46,10 +52,10 @@ class SubfleetTest extends TestCase
public function testSubfleetFaresOverride()
{
$fare_svc = app('App\Services\FareService');
$fare_svc = app(FareService::class);
$subfleet = factory(App\Models\Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create();
$subfleet = factory(Subfleet::class)->create();
$fare = factory(Fare::class)->create();
$fare_svc->setForSubfleet($subfleet, $fare, [
'price' => 50, 'capacity' => 400,

View File

@ -1,29 +1,36 @@
<?php
namespace Tests;
use App\Contracts\Unit;
use App\Exceptions\Handler;
use App\Repositories\SettingRepository;
use App\Services\DatabaseService;
use Carbon\Carbon;
use DateTimeImmutable;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use Illuminate\Testing\TestResponse;
use Tests\CreatesApplication;
use Tests\TestData;
use ReflectionClass;
class TestCase extends Illuminate\Foundation\Testing\TestCase
/**
* Test cases should extend this class
*/
abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
{
use TestData;
use CreatesApplication;
/**
* The base URL to use while testing the application.
*
* @var string
*/
public static $prefix = '/api';
@ -31,6 +38,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
protected $baseUrl = 'http://localhost';
protected $connectionsToTransact = ['test'];
/** @var \App\Models\User */
protected $user;
protected static $auth_headers = [
@ -53,11 +61,31 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
Artisan::call('database:create', ['--reset' => true]);
Artisan::call('migrate:refresh', ['--env' => 'testing']);
// $this->disableExceptionHandling();
}
public function tearDown(): void
/**
* https://stackoverflow.com/a/41945739
* https://gist.github.com/adamwathan/c9752f61102dc056d157
*/
protected function disableExceptionHandling()
{
parent::tearDown();
$this->app->instance(ExceptionHandler::class, new class() extends Handler {
public function __construct()
{
}
public function report(\Throwable $e)
{
// no-op
}
public function render($request, \Throwable $e)
{
throw $e;
}
});
}
/**
@ -200,13 +228,13 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
* @param $methodName
* @param array $parameters
*
* @throws ReflectionException
* @throws \ReflectionException
*
* @return mixed
*/
public function invokeMethod(&$object, $methodName, array $parameters = [])
{
$reflection = new \ReflectionClass(get_class($object));
$reflection = new ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
@ -228,7 +256,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
$this->transformData($value);
}
if (is_subclass_of($value, App\Contracts\Unit::class)) {
if (is_subclass_of($value, Unit::class)) {
$data[$key] = $value->__toString();
}
@ -249,9 +277,9 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
* @param array $headers
* @param null $user
*
* @return Illuminate\Testing\TestResponse
* @return \Illuminate\Testing\TestResponse
*/
public function get($uri, array $headers = [], $user = null): Illuminate\Testing\TestResponse
public function get($uri, array $headers = [], $user = null): TestResponse
{
$req = parent::get($uri, $this->headers($user, $headers));
if ($req->isClientError() || $req->isServerError()) {

View File

@ -1,5 +1,7 @@
<?php
namespace Tests;
use App\Exceptions\PilotIdNotFound;
use App\Exceptions\UserPilotIdExists;
use App\Models\User;
@ -35,7 +37,7 @@ class UserTest extends TestCase
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$user = factory(App\Models\User::class)->create([
$user = factory(\App\Models\User::class)->create([
'rank_id' => $rank->id,
]);
@ -95,7 +97,7 @@ class UserTest extends TestCase
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$user = factory(App\Models\User::class)->create([
$user = factory(\App\Models\User::class)->create([
'rank_id' => $rank->id,
]);
@ -136,17 +138,17 @@ class UserTest extends TestCase
{
// Add subfleets and aircraft, but also add another
// set of subfleets
$airport = factory(App\Models\Airport::class)->create();
$airport = factory(\App\Models\Airport::class)->create();
$subfleetA = $this->createSubfleetWithAircraft(2, $airport->id);
$subfleetB = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$user = factory(App\Models\User::class)->create([
$user = factory(\App\Models\User::class)->create([
'curr_airport_id' => $airport->id,
'rank_id' => $rank->id,
]);
$flight = factory(App\Models\Flight::class)->create([
$flight = factory(\App\Models\Flight::class)->create([
'airline_id' => $user->airline_id,
'dpt_airport_id' => $airport->id,
]);
@ -201,8 +203,8 @@ class UserTest extends TestCase
public function testUserPilotIdChangeAlreadyExists()
{
$this->expectException(UserPilotIdExists::class);
$user1 = factory(App\Models\User::class)->create(['id' => 1]);
$user2 = factory(App\Models\User::class)->create(['id' => 2]);
$user1 = factory(\App\Models\User::class)->create(['id' => 1]);
$user2 = factory(\App\Models\User::class)->create(['id' => 2]);
// Now try to change the original user's pilot_id to 2 (should conflict)
$this->userSvc->changePilotId($user1, 2);
@ -214,7 +216,7 @@ class UserTest extends TestCase
public function testUserPilotIdSplit(): void
{
/** @var \App\Models\User $user */
$user = factory(App\Models\User::class)->create();
$user = factory(\App\Models\User::class)->create();
$found_user = $this->userSvc->findUserByPilotId($user->ident);
$this->assertEquals($user->id, $found_user->id);
@ -229,7 +231,7 @@ class UserTest extends TestCase
public function testUserPilotIdSplitInvalidId(): void
{
/** @var \App\Models\User $user */
$user = factory(App\Models\User::class)->create();
$user = factory(\App\Models\User::class)->create();
$this->expectException(PilotIdNotFound::class);
$this->userSvc->findUserByPilotId($user->airline->iata);
@ -240,13 +242,13 @@ class UserTest extends TestCase
*/
public function testUserPilotIdAdded()
{
$new_user = factory(App\Models\User::class)->make()->toArray();
$new_user = factory(\App\Models\User::class)->make()->toArray();
$new_user['password'] = Hash::make('secret');
$user = $this->userSvc->createUser($new_user);
$this->assertEquals($user->id, $user->pilot_id);
// Add a second user
$new_user = factory(App\Models\User::class)->make()->toArray();
$new_user = factory(\App\Models\User::class)->make()->toArray();
$new_user['password'] = Hash::make('secret');
$user2 = $this->userSvc->createUser($new_user);
$this->assertEquals($user2->id, $user2->pilot_id);
@ -256,7 +258,7 @@ class UserTest extends TestCase
$this->assertEquals(3, $user->pilot_id);
// Create a new user and the pilot_id should be 4
$user3 = factory(App\Models\User::class)->create();
$user3 = factory(\App\Models\User::class)->create();
$this->assertEquals(4, $user3->pilot_id);
}

View File

@ -1,5 +1,7 @@
<?php
namespace Tests;
use App\Support\ICAO;
use App\Support\Units\Time;
use App\Support\Utils;
@ -14,7 +16,7 @@ class UtilsTest extends TestCase
}
/**
* @throws Exception
* @throws \Exception
*/
public function testSecondsToTimeParts()
{

View File

@ -1,5 +1,7 @@
<?php
namespace Tests;
use App\Repositories\KvpRepository;
use App\Services\VersionService;