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
16 changes: 10 additions & 6 deletions app/cdash/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ add_legacy_unit_test(/PHPUnitTest)

add_legacy_unit_test(/CDash/ServiceContainer)

add_unit_test(/Unit/Console/Command/ValidateXmlCommandTest)

add_unit_test(/Unit/GraphQL/SchemaValidationTest)

add_php_test(seconds_from_interval)
Expand Down Expand Up @@ -253,15 +251,17 @@ add_feature_test_in_transaction(/Feature/Monitor)

add_feature_test_in_transaction(/Feature/PasswordRotation)

add_feature_test_in_transaction(/Feature/PurgeUnusedProjectsCommand)
add_feature_test_in_transaction(/Feature/Console/PurgeUnusedProjectsCommandTest)

add_feature_test_in_transaction(/Feature/Jobs/PruneJobsTest)

add_feature_test_in_transaction(/Feature/Jobs/PruneAuthTokensTest)

add_feature_test_in_transaction(/Feature/UserCommand)
add_feature_test_in_transaction(/Feature/Console/SaveUserCommandTest)

add_feature_test_in_transaction(/Feature/Console/RemoveUserCommandTest)

add_feature_test_in_transaction(/Feature/EmailTestCommandTest)
add_feature_test_in_transaction(/Feature/Console/EmailTestCommandTest)

add_feature_test_in_transaction(/Feature/Jobs/NotifyExpiringAuthTokensTest)

Expand Down Expand Up @@ -341,10 +341,14 @@ add_feature_test_in_transaction(/Feature/Services/SiteServiceTest)

add_feature_test_in_transaction(/Feature/Middleware/AuthenticateTokenTest)

add_feature_test_in_transaction(/Feature/AutoRemoveBuildsCommand)
add_feature_test_in_transaction(/Feature/Console/AutoRemoveBuildsCommandTest)

add_feature_test_in_transaction(/Feature/Console/QueueSubmissionsCommandTest)

add_feature_test_in_transaction(/Feature/Console/DeleteProjectCommandTest)

add_feature_test_in_transaction(/Feature/Console/ValidateXmlCommandTest)

add_feature_test_in_transaction(/Feature/Submission/XmlSubmissionTest)

add_feature_test_in_transaction(/Feature/Submission/UnparsedSubmissionTest)
Expand Down
72 changes: 18 additions & 54 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21678,11 +21678,20 @@ parameters:
count: 1
path: tests/BrowserTestCase.php

-
rawMessage: '''
Call to deprecated method forceRootUrl() of class Illuminate\Routing\UrlGenerator:
Use useOrigin
'''
identifier: staticMethod.deprecated
count: 4
path: tests/Feature/CDashTest.php

-
rawMessage: Access to an undefined property CDash\Model\Build::$Endime.
identifier: property.notFound
count: 2
path: tests/Feature/AutoRemoveBuildsCommand.php
path: tests/Feature/Console/AutoRemoveBuildsCommandTest.php

-
rawMessage: '''
Expand All @@ -21691,7 +21700,7 @@ parameters:
'''
identifier: method.deprecated
count: 3
path: tests/Feature/AutoRemoveBuildsCommand.php
path: tests/Feature/Console/AutoRemoveBuildsCommandTest.php

-
rawMessage: '''
Expand All @@ -21700,28 +21709,25 @@ parameters:
'''
identifier: method.deprecated
count: 1
path: tests/Feature/AutoRemoveBuildsCommand.php
path: tests/Feature/Console/AutoRemoveBuildsCommandTest.php

-
rawMessage: 'Cannot call method fetchColumn() on PDOStatement|false.'
identifier: method.nonObject
count: 3
path: tests/Feature/AutoRemoveBuildsCommand.php
path: tests/Feature/Console/AutoRemoveBuildsCommandTest.php

-
rawMessage: 'Parameter #1 $stmt of method CDash\Database::execute() expects PDOStatement, PDOStatement|false given.'
identifier: argument.type
count: 3
path: tests/Feature/AutoRemoveBuildsCommand.php
path: tests/Feature/Console/AutoRemoveBuildsCommandTest.php

-
rawMessage: '''
Call to deprecated method forceRootUrl() of class Illuminate\Routing\UrlGenerator:
Use useOrigin
'''
identifier: staticMethod.deprecated
count: 4
path: tests/Feature/CDashTest.php
rawMessage: 'You should use assertSame() instead of assertEquals(), because both values are scalars of the same type'
identifier: phpunit.assertEquals
count: 2
path: tests/Feature/Console/ValidateXmlCommandTest.php

-
rawMessage: 'Method Tests\Feature\GlobalInvitationAcceptanceTest::createInvitation() throws checked exception OverflowException but it''s missing from the PHPDoc @throws tag.'
Expand Down Expand Up @@ -22116,18 +22122,6 @@ parameters:
count: 1
path: tests/Feature/ProjectPermissions.php

-
rawMessage: Class Tests\Feature\PurgeUnusedProjectsCommand has an uninitialized property $project1. Give it default value or assign it in the constructor.
identifier: property.uninitialized
count: 1
path: tests/Feature/PurgeUnusedProjectsCommand.php

-
rawMessage: Class Tests\Feature\PurgeUnusedProjectsCommand has an uninitialized property $project2. Give it default value or assign it in the constructor.
identifier: property.uninitialized
count: 1
path: tests/Feature/PurgeUnusedProjectsCommand.php

-
rawMessage: '''
Call to deprecated method forceRootUrl() of class Illuminate\Routing\UrlGenerator:
Expand All @@ -22146,36 +22140,6 @@ parameters:
count: 1
path: tests/Feature/Services/ProjectServiceTest.php

-
rawMessage: Cannot access property $admin on App\Models\User|null.
identifier: property.nonObject
count: 1
path: tests/Feature/UserCommand.php

-
rawMessage: Cannot access property $institution on App\Models\User|null.
identifier: property.nonObject
count: 1
path: tests/Feature/UserCommand.php

-
rawMessage: Property Tests\Feature\UserCommand::$user has no type specified.
identifier: missingType.property
count: 1
path: tests/Feature/UserCommand.php

-
rawMessage: 'You should use assertSame() instead of assertEquals(), because both values are scalars of the same type'
identifier: phpunit.assertEquals
count: 5
path: tests/Feature/UserCommand.php

-
rawMessage: 'You should use assertSame() instead of assertEquals(), because both values are scalars of the same type'
identifier: phpunit.assertEquals
count: 2
path: tests/Unit/Console/Command/ValidateXmlCommandTest.php

-
rawMessage: 'Parameter #1 $objectOrClass of class ReflectionClass constructor expects class-string<T of object>|T of object, array<string>|string given.'
identifier: argument.type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Feature;
namespace Tests\Feature\Console;

use App\Models\Project;
use CDash\Database;
Expand All @@ -11,7 +11,7 @@
use Tests\TestCase;
use Tests\Traits\CreatesProjects;

class AutoRemoveBuildsCommand extends TestCase
class AutoRemoveBuildsCommandTest extends TestCase
{
use CreatesProjects;
use DatabaseTransactions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Feature;
namespace Tests\Feature\Console;

use App\Mail\TestEmail;
use Illuminate\Foundation\Testing\DatabaseTransactions;
Expand Down
39 changes: 39 additions & 0 deletions tests/Feature/Console/PurgeUnusedProjectsCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Tests\Feature\Console;

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
use Tests\TestCase;
use Tests\Traits\CreatesProjects;

class PurgeUnusedProjectsCommandTest extends TestCase
{
use CreatesProjects;
use DatabaseTransactions;

public function testDeletesProjectsWithoutBuilds(): void
{
$project = $this->makePublicProject();

$this->expectOutputString("Deleting project: {$project->name}\n");
Artisan::call('projects:clean');

self::assertModelMissing($project);
}

public function testKeepsProjectsWithBuilds(): void
{
$project = $this->makePublicProject();
$project->builds()->create([
'name' => Str::uuid()->toString(),
'uuid' => Str::uuid()->toString(),
]);

$this->expectOutputString('');
Artisan::call('projects:clean');

self::assertModelExists($project);
}
}
37 changes: 37 additions & 0 deletions tests/Feature/Console/RemoveUserCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Tests\Feature\Console;

use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;

class RemoveUserCommandTest extends TestCase
{
use DatabaseTransactions;

public function testRequiresEmail(): void
{
Artisan::call('user:remove');

self::assertSame("You must specify the --email option\n", Artisan::output());
}

public function testFailsForNonexistentUser(): void
{
Artisan::call('user:remove', ['--email' => 'does-not-exist@example.com']);

self::assertSame("User does-not-exist@example.com does not exist\n", Artisan::output());
}

public function testDeletesUser(): void
{
$user = User::factory()->create();

Artisan::call('user:remove', ['--email' => $user->email]);

self::assertSame("Deleted user {$user->email}\n", Artisan::output());
self::assertModelMissing($user);
}
}
110 changes: 110 additions & 0 deletions tests/Feature/Console/SaveUserCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Tests\Feature\Console;

use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;

class SaveUserCommandTest extends TestCase
{
use DatabaseTransactions;

public function testRequiresEmail(): void
{
Artisan::call('user:save', ['--firstname' => 'Jane']);

self::assertSame("You must specify the --email option\n", Artisan::output());
}

public function testCreatesUser(): void
{
$email = Str::uuid()->toString() . '@example.com';

Artisan::call('user:save', [
'--email' => $email,
'--firstname' => 'Jane',
'--lastname' => 'Doe',
'--institution' => 'Kitware',
'--password' => 'correct horse battery staple',
]);

self::assertSame("Created $email\n", Artisan::output());
$user = User::where('email', $email)->firstOrFail();
self::assertSame([
'firstname' => 'Jane',
'lastname' => 'Doe',
'institution' => 'Kitware',
'admin' => false,
], $user->only(['firstname', 'lastname', 'institution', 'admin']));
self::assertTrue(Hash::check('correct horse battery staple', $user->password));
}

/**
* @return array<string,array{string}>
*/
public static function requiredNewUserOptionCases(): array
{
return [
'firstname' => ['firstname'],
'lastname' => ['lastname'],
'institution' => ['institution'],
'password' => ['password'],
];
}

#[DataProvider('requiredNewUserOptionCases')]
public function testCreateRequiresOption(string $option): void
{
$email = Str::uuid()->toString() . '@example.com';
$options = [
'--email' => $email,
'--firstname' => 'Jane',
'--lastname' => 'Doe',
'--institution' => 'Kitware',
'--password' => 'correct horse battery staple',
];
unset($options["--$option"]);

Artisan::call('user:save', $options);

self::assertSame("You must specify the --$option option when creating a new user\n", Artisan::output());
self::assertDatabaseMissing(User::class, ['email' => $email]);
}

public function testUpdatesOnlyGivenOptions(): void
{
$user = User::factory()->create([
'firstname' => 'Jane',
'lastname' => 'Doe',
'institution' => 'Kitware',
]);
$password = $user->password;

Artisan::call('user:save', ['--email' => $user->email, '--institution' => 'CTest']);

self::assertSame("Updated {$user->email}\n", Artisan::output());
$user->refresh();
self::assertSame([
'firstname' => 'Jane',
'lastname' => 'Doe',
'institution' => 'CTest',
'admin' => false,
], $user->only(['firstname', 'lastname', 'institution', 'admin']));
self::assertSame($password, $user->password);
}

public function testGrantsAdmin(): void
{
$user = User::factory()->create();

Artisan::call('user:save', ['--email' => $user->email, '--admin' => '1']);

self::assertSame("Updated {$user->email}\n", Artisan::output());
self::assertTrue($user->refresh()->admin);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Unit\Console\Command;
namespace Tests\Feature\Console;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
Expand Down
Loading
Loading