Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhemphill committed Mar 22, 2024
1 parent b9fc687 commit e48df28
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 141 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
composer.lock
phpunit.xml
.phpunit.result.cache
/.idea
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
],
"type": "project",
"require": {
"illuminate/support": "^5.7|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0"
"illuminate/database": "^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0"
},
"require-dev": {
"mockery/mockery": "^1.0",
"orchestra/database": "3.8.*",
"orchestra/testbench": "3.8.*",
"phpunit/phpunit": "^7.5"
"orchestra/database": "^6.19|^7.0|^8.0",
"orchestra/testbench": "^6.19|^7.0|^8.0",
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
</php>
</phpunit>
34 changes: 0 additions & 34 deletions tests/Factories/UserFactory.php

This file was deleted.

8 changes: 7 additions & 1 deletion tests/Fixtures/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
namespace Hemp\Presenter\Tests\Fixtures;

use Hemp\Presenter\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
use Notifiable, SoftDeletes, Presentable;
use Notifiable, SoftDeletes, Presentable, HasFactory;

protected static function newFactory()
{
return UserFactory::new();
}

/**
* The attributes that are mass assignable.
Expand Down
31 changes: 31 additions & 0 deletions tests/Fixtures/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Hemp\Presenter\Tests\Fixtures;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<\Illuminate\Database\Eloquent\Model>
*/
protected $model = User::class;

/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
}
10 changes: 10 additions & 0 deletions tests/Fixtures/UserWithDefaultPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

namespace Hemp\Presenter\Tests\Fixtures;

use Hemp\Presenter\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class UserWithDefaultPresenter extends User
{
use HasFactory;

protected $table = 'users';

public $defaultPresenter = UserProfilePresenter::class;

protected static function newFactory()
{
return UserWithDefaultPresenterFactory::new();
}
}
8 changes: 8 additions & 0 deletions tests/Fixtures/UserWithDefaultPresenterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Hemp\Presenter\Tests\Fixtures;

class UserWithDefaultPresenterFactory extends UserFactory
{
protected $model = UserWithDefaultPresenter::class;
}
79 changes: 30 additions & 49 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,52 @@

namespace Hemp\Presenter\Tests;

use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Schema;
use Orchestra\Testbench\TestCase;

abstract class IntegrationTest extends TestCase
{
/**
* Setup the test case.
*
* @return void
*/
public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Hash::driver('bcrypt')->setRounds(4);
$this->setUpDatabase();
}

$this->withFactories(__DIR__.'/Factories');
protected function setUpDatabase()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});

$this->loadMigrations();
$this->registerRoutes();
}

protected function loadMigrations()
protected function getPackageProviders($app)
{
$this->loadMigrationsFrom([
'--database' => 'sqlite',
'--realpath' => realpath(__DIR__.'/Migrations'),
return [
\Hemp\Presenter\PresenterServiceProvider::class
];
}

protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}

/**
* Register the package's routes for testing resources.
*
* @return void
*/
protected function registerRoutes()
protected function defineWebRoutes($router)
{
Route::get('/users', function () {
return \Hemp\Presenter\Tests\Fixtures\User::all()->present(function ($user) {
Expand All @@ -52,32 +61,4 @@ protected function registerRoutes()
});
});
}

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'sqlite');
$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}

protected function getPackageAliases($app)
{
return [
// 'Presenter' => 'Hemp\Presenter\Facades\Presenter'
];
}

protected function getPackageProviders($app)
{
return [\Hemp\Presenter\PresenterServiceProvider::class];
}
}
Loading

0 comments on commit e48df28

Please sign in to comment.