8000 add testing juegos · JAVI-CC/Laravel-API-Server@ee92f29 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee92f29

Browse files
committed
add testing juegos
1 parent 0a31701 commit ee92f29

28 files changed

+671
-88
lines changed

.env.example

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ DB_DATABASE=api
1313
DB_USERNAME=user
1414
DB_PASSWORD=12345678
1515

16+
DB_TEST_CONNECTION=mysql
17+
DB_TEST_HOST=db
18+
DB_TEST_PORT=3306
19+
DB_TEST_DATABASE=api-test
20+
DB_TEST_USERNAME=user
21+
DB_TEST_PASSWORD=12345678
22+
1623
BROADCAST_DRIVER=log
1724
CACHE_DRIVER=file
1825
QUEUE_CONNECTION=sync

app/Models/Imagen.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Illuminate\Support\Facades\File;
55

66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Support\Facades\Storage;
78

89
class Imagen extends Model
910
{
< A3E2 button class="Button Button--iconOnly Button--invisible ExpandableHunkHeaderDiffLine-module__expand-button-line--rnQN5 ExpandableHunkHeaderDiffLine-module__expand-button-unified--j86KQ" aria-label="Expand file from line 10 to line 18" data-direction="all" aria-hidden="true" tabindex="-1">
@@ -17,10 +18,11 @@ public function upload($id, $slug, $imagen, $nombre)
1718
$imagen = str_replace(' ', '+', $imagen);
1819
$imagen = base64_decode($imagen);
1920

20-
$filename = "eliminar." . $extension;
21+
//$filename = "eliminar." . $extension;
2122
$filenamePNG = $id . "-" . $slug . ".png";
22-
file_put_contents('media/'.$nombre.'/'.$filename, $imagen);
23-
imagepng(imagecreatefromstring(file_get_contents(public_path('media/'.$nombre.'/' . $filename))), public_path('media/'.$nombre.'/' . $filenamePNG));
23+
Storage::disk('juegos')->put($nombre.'/' . $filenamePNG, $imagen);
24+
//file_put_contents('media/'.$nombre.'/'.$filename, $imagen);
25+
//imagepng(imagecreatefromstring(file_get_contents(public_path($nombre.'/' . $filename))), public_path($nombre.'/' . $filenamePNG));
2426
File::delete(File::glob(public_path('media/'.$nombre.'/eliminar.*')));
2527
}
2628

app/Models/Juego.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Illuminate\Support\Facades\Validator;
1212
use App\Traits\HasFind;
1313
use App\Traits\HasSlug;
14-
14+
use Illuminate\Database\Eloquent\Factories\HasFactory;
1515

1616
/**
1717
* @OA\Schema(
@@ -31,7 +31,7 @@
3131
*/
3232
class Juego extends Model
3333
{
34-
use HasFind, HasSlug;
34+
use HasFind, HasSlug, HasFactory;
3535

3636
public $timestamps = false;
3737
protected $table = 'juegos';

app/Models/User.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Models;
44

55
use Illuminate\Contracts\Auth\MustVerifyEmail;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
67
use Illuminate\Foundation\Auth\User as Authenticatable;
78
use Illuminate\Notifications\Notifiable;
89
use Laravel\Sanctum\HasApiTokens;
@@ -20,7 +21,7 @@
2021
**/
2122
class User extends Authenticatable
2223
{
23-
use Notifiable, HasApiTokens;
24+
use Notifiable, HasApiTokens, HasFactory;
2425

2526
/**
2627
* The attributes that are mass assignable.

config/database.php

+20
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@
6363
]) : [],
6464
],
6565

66+
'mysql_testing' => [
67+
'driver' => 'mysql',
68+
'url' => env('DATABASE_URL'),
69+
'host' => env('DB_TEST_HOST', '127.0.0.1'),
70+
'port' => env('DB_TEST_PORT', '3306'),
71+
'database' => env('DB_TEST_DATABASE', 'forge'),
72+
'username' => env('DB_TEST_USERNAME', 'forge'),
73+
'password' => env('DB_TEST_PASSWORD', ''),
74+
'unix_socket' => env('DB_TEST_SOCKET', ''),
75+
'charset' => 'utf8mb4',
76+
'collation' => 'utf8mb4_unicode_ci',
77+
'prefix' => '',
78+
'prefix_indexes' => true,
79+
'strict' => true,
80+
'engine' => null,
81+
'options' => extension_loaded('pdo_mysql') ? array_filter([
82+
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
83+
]) : [],
84+
],
85+
6686
'pgsql' => [
6787
'driver' => 'pgsql',
6888
'url' => env('DATABASE_URL'),

config/filesystems.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@
5050
'public' => [
5151
'driver' => 'local',
5252
'root' => storage_path('app/public'),
53-
'url' => env('APP_URL').'/storage',
53+
'url' => env('APP_URL') . '/storage',
54+
'visibility' => 'public',
55+
],
56+
57+
'juegos' => [
58+
'driver' => 'local',
59+
'root' => public_path() . '/media',
60+
'url' => env('APP_URL') . '/storage',
5461
'visibility' => 'public',
5562
],
5663

database/factories/JuegoFactory.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
/**
8+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Juego>
9+
*/
10+
class JuegoFactory extends Factory
11+
{
12+
/**
13+
* Define the model's default state.
14+
*
15+
* @return array<string, mixed>
16+
*/
17+
public function definition(): array
18+
{
19+
return [
20+
'nombre' => fake()->unique()->name(),
21+
'descripcion' => fake()->text(),
22+
'fecha' => fake()->dateTimeBetween()->format('Y-m-d'),
23+
'slug' => fake()->unique()->slug(),
24+
];
25+
}
26+
}

database/factories/UserFactory.php

+21-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
<?php
22

3-
/** @var \Illuminate\Database\Eloquent\Factory $factory */
3+
namespace Database\Factories;
44

5-
use App\User;
6-
use Faker\Generator as Faker;
7-
use Illuminate\Support\Str;
5+
use Illuminate\Database\Eloquent\Factories\Factory;
86

9-
/*
10-
|--------------------------------------------------------------------------
11-
| Model Factories
12-
|--------------------------------------------------------------------------
13-
|
14-
| This directory should contain each of the model factory definitions for
15-
| your application. Factories provide a convenient way to generate new
16-
| model instances for testing / seeding your application's database.
17-
|
18-
*/
19-
20-
$factory->define(User::class, function (Faker $faker) {
21-
return [
22-
'name' => $faker->name,
23-
'email' => $faker->unique()->safeEmail,
24-
'email_verified_at' => now(),
25-
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
26-
'remember_token' => Str::random(10),
27-
];
28-
});
7+
/**
8+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
9+
*/
10+
class UserFactory extends Factory
11+
{
12+
/**
13+
* Define the model's default state.
14+
*
15+
* @return array<string, mixed>
16+
*/
17+
public function definition(): array
18+
{
19+
return [
20+
'name' => fake()->name(),
21+
'email' => fake()->unique()->safeEmail(),
22+
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
23+
];
24+
}
25+
}

database/seeds/DesarrolladoraSeeder.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use Illuminate\Database\Seeder;
46
use App\Models\Desarrolladora;
57
use Illuminate\Support\Facades\DB;

database/seeds/GeneroSeeder.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use Illuminate\Database\Seeder;
46
use App\Models\Genero;
57
use Illuminate\Support\Facades\DB;

database/seeds/JuegableSeeder.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use Illuminate\Database\Seeder;
6+
use Illuminate\Support\Facades\DB;
47

58
class JuegableSeeder extends Seeder
69
{

database/seeds/JuegoSeeder.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use Illuminate\Database\Seeder;
46
use App\Models\Juego;
57
use Illuminate\Support\Facades\DB;

database/seeds/UserSeeder.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Database\Seeders;
4+
35
use Illuminate\Database\Seeder;
46
use Illuminate\Support\Facades\Hash;
57

phpunit.xml

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
colors="true">
5+
colors="true"
6+
>
67
<testsuites>
78
<testsuite name="Unit">
8-
<directory suffix="Test.php">./tests/Unit</directory>
9+
<directory>tests/Unit</directory>
910
</testsuite>
10-
1111
<testsuite name="Feature">
12-
<directory suffix="Test.php">./tests/Feature</directory>
12+
<directory>tests/Feature</directory>
1313
</testsuite>
1414
</testsuites>
15-
<filter>
16-
<whitelist processUncoveredFilesFromWhitelist="true">
17-
<directory suffix=".php">./app</directory>
18-
</whitelist>
19-
</filter>
15+
<source>
16+
<include>
17+
<directory>app</directory>
18+
</include>
19+
</source>
2020
<php>
21-
<server name="APP_ENV" value="testing"/>
22-
<server name="BCRYPT_ROUNDS" value="4"/>
23-
<server name="CACHE_DRIVER" value="array"/>
24-
<server name="DB_CONNECTION" value="sqlite"/>
25-
<server name="DB_DATABASE" value=":memory:"/>
26-
<server name="MAIL_DRIVER" value="array"/>
27-
<server name="QUEUE_CONNECTION" value="sync"/>
28-
<server name="SESSION_DRIVER" value="array"/>
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="mysql_testing"/>
25+
<env name="DB_DATABASE" value="juegos-test"/>
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+
<server name='HTTP_HOST' value='http://localhost' />
2931
</php>
3032
</phpunit>
-105 KB
Binary file not shown.
70 Bytes
Loading

0 commit comments

Comments
 (0)
0