Skip to content

Commit

Permalink
Setup testing, removed some dependencies from the App namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
vagrant committed Nov 11, 2022
1 parent acd431b commit f18c744
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 6 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"Warning":6,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testAdministrationRoute":3,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testModuleRegistration":5,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testConstructor":3,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testIfApiIsUnauthorized":4,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testTitleConfiguation":4},"times":{"ReinVanOyen\\Cmf\\Tests\\Component\\TextFieldTest::testName":0.12,"ReinVanOyen\\Cmf\\Tests\\Component\\TextFieldTest::test_name":0.097,"Warning":0,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testConstructor":0.114,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testAdministrationRoute":0.043,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testIfApiIsUnauthorized":0.039,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testModuleRegistration":0.005,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testTitleConfiguation":0.159,"ReinVanOyen\\Cmf\\Tests\\Component\\CmfTest::testModulesCount":0.011}}
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@
"spatie/temporary-directory": "^1.3",
"intervention/image": "^2.7"
},
"require-dev": {
"orchestra/testbench": "^7.11"
},
"autoload": {
"psr-4": {
"ReinVanOyen\\Cmf\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ReinVanOyen\\Cmf\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"ReinVanOyen\\Cmf\\CmfServiceProvider"
]
}
},
"scripts": {
"test": [
"./vendor/bin/phpunit -c phpunit.xml"
]
}
}
11 changes: 11 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<phpunit>
<testsuites>
<testsuite name="Package Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="DB_CONNECTION" value="testing"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
</php>
</phpunit>
2 changes: 1 addition & 1 deletion src/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ReinVanOyen\Cmf\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use ReinVanOyen\Cmf\Http\Resources\ModelResource;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/ComponentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ReinVanOyen\Cmf\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use ReinVanOyen\Cmf\MakeableStorage;
use ReinVanOyen\Cmf\PathResolver;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ReinVanOyen\Cmf\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Routing\Controller;
use ReinVanOyen\Cmf\Cmf;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ReinVanOyen\Cmf\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/ModulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ReinVanOyen\Cmf\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use ReinVanOyen\Cmf\Cmf;
use ReinVanOyen\Cmf\PathResolver;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
};

Route::middleware([
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
Authenticate::class,
DispatchServingCmfEvent::class,
Expand Down
27 changes: 27 additions & 0 deletions tests/CmfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace ReinVanOyen\Cmf\Tests\Component;

use ReinVanOyen\Cmf\Cmf;
use ReinVanOyen\Cmf\Tests\TestCase;

class CmfTest extends TestCase
{
public function testTitleConfiguation()
{
$this->assertEquals('Test cmf', app(Cmf::class)->getTitle());
}

public function testIfApiIsUnauthorized()
{
$response = $this->withExceptionHandling()
->get('/cmf/api/modules');

$response->assertStatus(401);
}

public function testModulesCount()
{
$this->assertCount(1, app(Cmf::class)->getModules());
}
}
69 changes: 69 additions & 0 deletions tests/Fixtures/Meta/UserMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace ReinVanOyen\Cmf\Tests\Fixtures\Meta;

use ReinVanOyen\Cmf\Tests\Fixtures\Models\User;
use ReinVanOyen\Cmf\Components\PasswordField;
use ReinVanOyen\Cmf\Components\TextField;
use ReinVanOyen\Cmf\Components\TextView;
use ReinVanOyen\Cmf\Meta;

class UserMeta extends Meta
{
/**
* @var string $model
*/
protected static $model = User::class;

/**
* @var string $title
*/
protected static $title = 'name';

/**
* @var array $search
*/
protected static $search = [
'name',
];

/**
* @var array $sort
*/
protected static $sort = [
'name' => 'asc',
];

/**
* @return array
*/
public static function index(): array
{
return [
TextView::make('name'),
TextView::make('email'),
];
}

/**
* @return array
*/
public static function create(): array
{
return [
TextField::make('name')
->validate(['required',]),
TextField::make('email')->validate(['required', 'email',]),
PasswordField::make('password')->validate(['required','min:8']),
];
}

public static function edit(): array
{
return [
TextField::make('name')->validate(['required',]),
TextField::make('email')->validate(['required', 'email',]),
PasswordField::make('password')->validate(['nullable','min:8',]),
];
}
}
43 changes: 43 additions & 0 deletions tests/Fixtures/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace ReinVanOyen\Cmf\Tests\Fixtures\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
70 changes: 70 additions & 0 deletions tests/Fixtures/Modules/UserModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace ReinVanOyen\Cmf\Tests\Fixtures\Modules;

use App\Cmf\Meta\UserMeta;
use ReinVanOyen\Cmf\Action\Action;
use ReinVanOyen\Cmf\Action\Create;
use ReinVanOyen\Cmf\Action\Delete;
use ReinVanOyen\Cmf\Action\Edit;
use ReinVanOyen\Cmf\Action\Index;
use ReinVanOyen\Cmf\Components\Link;
use ReinVanOyen\Cmf\Module;

class UserModule extends Module
{
/**
* @return string
*/
protected function title(): string
{
return 'Users';
}

/**
* @return string
*/
protected function icon()
{
return 'people';
}

/**
* @return Action
*/
public function index(): Action
{
return Index::make(UserMeta::class)
->action('edit')
->grid([1, 1, 0, 0,])
->header([
Link::make('New user', 'create')
->style('button'),
])
->search(['name',]);
}

/**
* @return Action
*/
public function create(): Action
{
return Create::make(UserMeta::class);
}

/**
* @return Action
*/
public function edit(): Action
{
return Edit::make(UserMeta::class);
}

/**
* @return Action
*/
public function delete(): Action
{
return Delete::make(UserMeta::class);
}
}
36 changes: 36 additions & 0 deletions tests/Migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
Loading

0 comments on commit f18c744

Please sign in to comment.