Skip to content

Commit 4ef6e2b

Browse files
Create UserManagementTest.php file
1 parent 1ab4a01 commit 4ef6e2b

File tree

5 files changed

+226
-48
lines changed

5 files changed

+226
-48
lines changed

_ide_helper.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4428,6 +4428,93 @@
44284428
/**
44294429
*
44304430
*
4431+
* @see \Illuminate\Encryption\Encrypter
4432+
*/ class Crypt {
4433+
/**
4434+
* Determine if the given key and cipher combination is valid.
4435+
*
4436+
* @param string $key
4437+
* @param string $cipher
4438+
* @return bool
4439+
* @static
4440+
*/ public static function supported($key, $cipher)
4441+
{
4442+
return \Illuminate\Encryption\Encrypter::supported($key, $cipher);
4443+
}
4444+
/**
4445+
* Create a new encryption key for the given cipher.
4446+
*
4447+
* @param string $cipher
4448+
* @return string
4449+
* @static
4450+
*/ public static function generateKey($cipher)
4451+
{
4452+
return \Illuminate\Encryption\Encrypter::generateKey($cipher);
4453+
}
4454+
/**
4455+
* Encrypt the given value.
4456+
*
4457+
* @param mixed $value
4458+
* @param bool $serialize
4459+
* @return string
4460+
* @throws \Illuminate\Contracts\Encryption\EncryptException
4461+
* @static
4462+
*/ public static function encrypt($value, $serialize = true)
4463+
{
4464+
/** @var \Illuminate\Encryption\Encrypter $instance */
4465+
return $instance->encrypt($value, $serialize);
4466+
}
4467+
/**
4468+
* Encrypt a string without serialization.
4469+
*
4470+
* @param string $value
4471+
* @return string
4472+
* @throws \Illuminate\Contracts\Encryption\EncryptException
4473+
* @static
4474+
*/ public static function encryptString($value)
4475+
{
4476+
/** @var \Illuminate\Encryption\Encrypter $instance */
4477+
return $instance->encryptString($value);
4478+
}
4479+
/**
4480+
* Decrypt the given value.
4481+
*
4482+
* @param string $payload
4483+
* @param bool $unserialize
4484+
* @return mixed
4485+
* @throws \Illuminate\Contracts\Encryption\DecryptException
4486+
* @static
4487+
*/ public static function decrypt($payload, $unserialize = true)
4488+
{
4489+
/** @var \Illuminate\Encryption\Encrypter $instance */
4490+
return $instance->decrypt($payload, $unserialize);
4491+
}
4492+
/**
4493+
* Decrypt the given string without unserialization.
4494+
*
4495+
* @param string $payload
4496+
* @return string
4497+
* @throws \Illuminate\Contracts\Encryption\DecryptException
4498+
* @static
4499+
*/ public static function decryptString($payload)
4500+
{
4501+
/** @var \Illuminate\Encryption\Encrypter $instance */
4502+
return $instance->decryptString($payload);
4503+
}
4504+
/**
4505+
* Get the encryption key that the encrypter is currently using.
4506+
*
4507+
* @return string
4508+
* @static
4509+
*/ public static function getKey()
4510+
{
4511+
/** @var \Illuminate\Encryption\Encrypter $instance */
4512+
return $instance->getKey();
4513+
}
4514+
}
4515+
/**
4516+
*
4517+
*
44314518
* @see https://carbon.nesbot.com/docs/
44324519
* @see https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Factory.php
44334520
* @method static \Illuminate\Support\Carbon create($year = 0, $month = 1, $day = 1, $hour = 0, $minute = 0, $second = 0, $tz = null)
@@ -17638,6 +17725,7 @@ class Bus extends \Illuminate\Support\Facades\Bus {}
1763817725
class Cache extends \Illuminate\Support\Facades\Cache {}
1763917726
class Config extends \Illuminate\Support\Facades\Config {}
1764017727
class Cookie extends \Illuminate\Support\Facades\Cookie {}
17728+
class Crypt extends \Illuminate\Support\Facades\Crypt {}
1764117729
class Date extends \Illuminate\Support\Facades\Date {}
1764217730
class DB extends \Illuminate\Support\Facades\DB {}
1764317731
class Eloquent extends \Illuminate\Database\Eloquent\Model { /**

phpunit.xml

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
>
7-
<testsuites>
8-
<testsuite name="Unit">
9-
<directory suffix="Test.php">./tests/Unit</directory>
10-
</testsuite>
11-
<testsuite name="Feature">
12-
<directory suffix="Test.php">./tests/Feature</directory>
13-
</testsuite>
14-
</testsuites>
15-
<coverage>
16-
<include>
17-
<directory suffix=".php">./app</directory>
18-
</include>
19-
</coverage>
20-
<php>
21-
<env name="APP_ENV" value="testing"/>
22-
<env name="BCRYPT_ROUNDS" value="4"/>
23-
<env name="CACHE_DRIVER" value="array"/>
24-
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
25-
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
26-
<env name="MAIL_MAILER" value="array"/>
27-
<env name="QUEUE_CONNECTION" value="sync"/>
28-
<env name="SESSION_DRIVER" value="array"/>
29-
<env name="TELESCOPE_ENABLED" value="false"/>
30-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
3+
<testsuites>
4+
<testsuite name="Unit">
5+
<directory suffix="Test.php">./tests/Unit</directory>
6+
</testsuite>
7+
<testsuite name="Feature">
8+
<directory suffix="Test.php">./tests/Feature</directory>
9+
</testsuite>
10+
</testsuites>
11+
<php>
12+
<env name="APP_ENV" value="testing"/>
13+
<env name="BCRYPT_ROUNDS" value="4"/>
14+
<env name="CACHE_DRIVER" value="array"/>
15+
<env name="DB_CONNECTION" value="sqlite"/>
16+
<env name="DB_DATABASE" value=":memory:"/>
17+
<env name="MAIL_MAILER" value="array"/>
18+
<env name="QUEUE_CONNECTION" value="sync"/>
19+
<env name="SESSION_DRIVER" value="array"/>
20+
<env name="TELESCOPE_ENABLED" value="false"/>
21+
</php>
22+
<source>
23+
<include>
24+
<directory suffix=".php">./app</directory>
25+
</include>
26+
</source>
3127
</phpunit>

phpunit.xml.bak

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Unit">
9+
<directory suffix="Test.php">./tests/Unit</directory>
10+
</testsuite>
11+
<testsuite name="Feature">
12+
<directory suffix="Test.php">./tests/Feature</directory>
13+
</testsuite>
14+
</testsuites>
15+
<coverage>
16+
<include>
17+
<directory suffix=".php">./app</directory>
18+
</include>
19+
</coverage>
20+
<php>
21+
<env name="APP_ENV" value="testing"/>
22+
<env name="BCRYPT_ROUNDS" value="4"/>
23+
<env name="CACHE_DRIVER" value="array"/>
24+
<env name="DB_CONNECTION" value="sqlite"/>
25+
<env name="DB_DATABASE" value=":memory:"/>
26+
<env name="MAIL_MAILER" value="array"/>
27+
<env name="QUEUE_CONNECTION" value="sync"/>
28+
<env name="SESSION_DRIVER" value="array"/>
29+
<env name="TELESCOPE_ENABLED" value="false"/>
30+
</php>
31+
</phpunit>

tests/Feature/ExampleTest.php

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use App\Models\User;
6+
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Tests\TestCase;
8+
9+
class UserManagementTest extends TestCase
10+
{
11+
use RefreshDatabase;
12+
13+
public function test_user_validation()
14+
{
15+
$this->actingAs(User::factory()->create());
16+
17+
$response = $this->post('/users', []);
18+
19+
$response->assertSessionHasErrors(['name', 'email', 'password', 'avatar']);
20+
}
21+
22+
public function test_user_update_feature()
23+
{
24+
$this->actingAs(User::factory()->create());
25+
26+
$user = User::factory()->create();
27+
28+
$this->put('/users/' . $user->id, [
29+
'name' => 'John Doe',
30+
'email' => 'updated@mail.com']);
31+
32+
$this->assertDatabaseHas('users', [
33+
'id' => $user->id,
34+
'name' => 'John Doe',
35+
'email' => 'updated@mail.com']
36+
);
37+
}
38+
39+
public function test_user_delete_feature()
40+
{
41+
$this->actingAs(User::factory()->create());
42+
43+
$user = User::factory()->create();
44+
45+
$response = $this->delete('/users/' . $user->id);
46+
47+
$response->assertRedirect('/');
48+
$this->assertDatabaseMissing('users', ['id' => $user->id]);
49+
}
50+
51+
public function test_user_delete_feature_with_invalid_id()
52+
{
53+
$this->actingAs(User::factory()->create());
54+
55+
$response = $this->withHeaders(['X-CSRF-TOKEN' => ''])
56+
->delete('/users/999');
57+
58+
$response->assertStatus(302);
59+
}
60+
61+
public function test_all_users_are_shown_on_index_page()
62+
{
63+
$this->actingAs(User::factory()->create());
64+
65+
$user = User::factory()->create();
66+
67+
$response = $this->get('/users');
68+
69+
$response->assertSee($user->name);
70+
}
71+
72+
public function test_user_creation_date_is_in_valid_format()
73+
{
74+
$this->actingAs(User::factory()->create());
75+
76+
$user = User::factory()->create();
77+
78+
$response = $this->get('/users');
79+
80+
$response->assertSee($user->created_at->format('d M Y'));
81+
}
82+
}

0 commit comments

Comments
 (0)