Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Sep 16, 2023
1 parent 09c8477 commit 6bb4aba
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions tests/Commands/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ public function testCreate(): void
]);
}

public function testCreateNotUniqueName(): void

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - Postgre - highest

Took 0.99s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - SQLite3 - highest

Took 0.93s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - MySQLi - highest

Took 0.87s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - highest

Took 1.11s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - SQLite3 - highest

Took 0.99s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - MySQLi - highest

Took 0.94s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - SQLSRV - highest

Took 1.13s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - SQLite3 - highest

Took 1.20s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - highest

Took 1.36s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.1 - MySQLi - highest

Took 1.22s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.1 - SQLite3 - highest

Took 1.11s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName

Check warning on line 66 in tests/Commands/UserTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - OCI8 - highest

Took 2.12s from 0.50s limit to run Tests\\Commands\\UserTest::testCreateNotUniqueName
{
$user = $this->createUser([
'username' => 'user1',
'email' => '[email protected]',
'password' => 'secret123',
]);

$this->setMockIo([
'Secret Passw0rd!',
'Secret Passw0rd!',
]);

command('shield:user create -n user1 -e [email protected]');

$this->assertStringContainsString(
'The Username field must contain a unique value.',
$this->io->getOutputs()
);
$this->assertStringContainsString(
'User creation aborted',
$this->io->getOutputs()
);

$users = model(UserModel::class);
$user = $users->findByCredentials(['email' => '[email protected]']);
$this->assertNull($user);
}

/**
* Create an active user.
*/
Expand Down Expand Up @@ -156,6 +185,35 @@ public function testChangename(): void
]);
}

public function testChangenameInvalidName(): void
{
$this->createUser([
'username' => 'user4',
'email' => '[email protected]',
'password' => 'secret123',
]);

$this->setMockIo(['y']);

command('shield:user changename -n user4 --new-name 1');

$this->assertStringContainsString(
'The Username field must be at least 3 characters in length.',
$this->io->getOutputs()
);
$this->assertStringContainsString(
'User name change aborted',
$this->io->getOutputs()
);

$users = model(UserModel::class);
$user = $users->findByCredentials(['email' => '[email protected]']);
$this->seeInDatabase($this->tables['users'], [
'id' => $user->id,
'username' => 'user4',
]);
}

public function testChangeemail(): void
{
$this->createUser([
Expand All @@ -181,6 +239,32 @@ public function testChangeemail(): void
]);
}

public function testChangeemailInvalidEmail(): void
{
$this->createUser([
'username' => 'user5',
'email' => '[email protected]',
'password' => 'secret123',
]);

$this->setMockIo(['y']);

command('shield:user changeemail -n user5 --new-email invalid');

$this->assertStringContainsString(
'The Email Address field must contain a valid email address.',
$this->io->getOutputs()
);
$this->assertStringContainsString(
'User email change aborted',
$this->io->getOutputs()
);

$users = model(UserModel::class);
$user = $users->findByCredentials(['email' => 'invalid']);
$this->assertNull($user);
}

public function testDelete(): void
{
$this->createUser([
Expand All @@ -203,6 +287,28 @@ public function testDelete(): void
$this->assertNull($user);
}

public function testDeleteById(): void
{
$user = $this->createUser([
'username' => 'user6',
'email' => '[email protected]',
'password' => 'secret123',
]);

$this->setMockIo(['y']);

command('shield:user delete -i ' . $user->id);

$this->assertStringContainsString(
'User "user6" deleted',
$this->io->getLastOutput()
);

$users = model(UserModel::class);
$user = $users->findByCredentials(['email' => '[email protected]']);
$this->assertNull($user);
}

public function testPassword(): void
{
$this->createUser([
Expand Down

0 comments on commit 6bb4aba

Please sign in to comment.