Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new tests #14

Merged
merged 41 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c686f6b
DTO classes coverage raised to 100%;
hans-thomas Sep 30, 2023
b54a409
Tests for Handler added;
hans-thomas Oct 8, 2023
5e6b85c
Apply fixes from StyleCI
StyleCIBot Oct 8, 2023
534c3e5
Merge pull request #10 from hans-thomas/analysis-DydE9y
hans-thomas Oct 8, 2023
f8462f7
Update .styleci.yml
hans-thomas Oct 8, 2023
57b8ddb
Refactor ErrorCode;
hans-thomas Oct 8, 2023
812ffb4
Tests added for ErrorCode;
hans-thomas Oct 8, 2023
9c9b3b2
Apply fixes from StyleCI
StyleCIBot Oct 8, 2023
9e5fe5a
Merge pull request #11 from hans-thomas/analysis-prmMx4
hans-thomas Oct 8, 2023
73acf16
Update ErrorCode.php
hans-thomas Oct 8, 2023
de69351
Merge branch 'adding-new-tests' of github.com:hans-thomas/valravn int…
hans-thomas Oct 8, 2023
96a2515
Router facade updated;
hans-thomas Oct 8, 2023
9c5dce3
Use Router facade in RoutingServiceTest;
hans-thomas Oct 8, 2023
8f85833
Apply fixes from StyleCI
StyleCIBot Oct 8, 2023
e8a2499
Merge pull request #12 from hans-thomas/analysis-rr6mnG
hans-thomas Oct 8, 2023
4d8adb7
More tests added for resolveRelatedIdToModel helper func;
hans-thomas Oct 8, 2023
cca1386
Apply fixes from StyleCI
StyleCIBot Oct 8, 2023
c825212
Merge pull request #13 from hans-thomas/analysis-KolMVQ
hans-thomas Oct 8, 2023
ece4653
More tests added for FilteringService;
hans-thomas Oct 9, 2023
feedafc
Apply fixes from StyleCI
StyleCIBot Oct 9, 2023
72d3a4c
move FilteringServiceTest to Filtering folder;
hans-thomas Oct 9, 2023
41ff9c9
Tests added for LikeFilter;
hans-thomas Oct 9, 2023
62f05ca
Tests added for OrderFilter;
hans-thomas Oct 9, 2023
1ff92b4
Tests added for OrderPivotFilter;
hans-thomas Oct 9, 2023
5aeac9c
Apply fixes from StyleCI
StyleCIBot Oct 9, 2023
85e520e
Tests added for WhereFilter;
hans-thomas Oct 9, 2023
e10c3ff
Apply fixes from StyleCI
StyleCIBot Oct 9, 2023
cc9ab07
Tests for WherePivotFilter;
hans-thomas Oct 9, 2023
f5043e7
Tests for WhereRelationFilter;
hans-thomas Oct 9, 2023
9ab5fad
Tests for WhereRelationLikeFilter;
hans-thomas Oct 9, 2023
4273a19
Merge branch 'adding-new-tests' of github.com:hans-thomas/valravn int…
hans-thomas Oct 9, 2023
ec2a549
Apply fixes from StyleCI
StyleCIBot Oct 9, 2023
0eea502
Tests for OrWhereRelationFilter;
hans-thomas Oct 9, 2023
5a3af85
Tests for OrWhereRelationLikeFilter;
hans-thomas Oct 9, 2023
61c483f
Apply fixes from StyleCI
StyleCIBot Oct 9, 2023
ba745e0
Update OrWhereRelationFilterTest.php
hans-thomas Oct 9, 2023
0b27375
Update OrWhereRelationLikeFilterTest.php
hans-thomas Oct 9, 2023
0a3e60f
More tests added;
hans-thomas Oct 9, 2023
0e13bab
Tests for Paginatable;
hans-thomas Oct 9, 2023
44a3b1f
Apply fixes from StyleCI
StyleCIBot Oct 9, 2023
55cb11e
Update codecov.yml
hans-thomas Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ use-tabs: false
finder:
exclude:
- "docs"
- "modules"
- "node_modules"
- "nova"
- "nova-components"
- "storage"
- "spark"
- "vendor"
name: "*.php"
not-name:
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ coverage:
status:
project:
default:
target: 73%
target: 87%
threshold: 1%
57 changes: 51 additions & 6 deletions src/Exceptions/ErrorCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,73 @@

namespace Hans\Valravn\Exceptions;

use Hans\Valravn\Exceptions\Package\PackageException;
use Illuminate\Support\Str;

abstract class ErrorCode
{
/**
* Prefix of defined codes.
*
* @var string
*/
protected static string $prefix = 'ECx';

/**
* Singleton instance of the class.
*
* @var self
*/
private static self $instance;

/**
* Make a singleton instance.
*
* @return static
*/
public static function make(): static
{
if (isset(self::$instance)) {
return self::$instance;
}

return self::$instance = new static();
}

/**
* @param string $name
*
* @throws ValravnException
*
* @return string
*/
public function __get(string $name)
{
return $this->{$name};
return self::__callStatic($name, []);
}

/**
* @param string $name
* @param array $arguments
*
* @throws ValravnException
*
* @return string
*/
public static function __callStatic(string $name, array $arguments)
{
if (property_exists(static::class, $name)) {
return static::$prefix.( new static() )->{$name};
$property = $name;
} elseif (property_exists(static::class, $camel = Str::of($name)->camel()->toString())) {
$property = $camel;
} elseif (property_exists(static::class, $snake = Str::of($name)->snake()->upper()->toString())) {
$property = $snake;
}

$property = Str::of($name)->snake()->upper()->toString();
if (property_exists(static::class, $property)) {
return static::$prefix.( new static() )->{$property};
if (isset($property)) {
return static::$prefix.(new static())->{$property};
}

return static::$prefix;
throw PackageException::errorCodeNotFound($name);
}
}
32 changes: 0 additions & 32 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,6 @@

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}

/**
* Render an exception into an HTTP response.
*
Expand Down
1 change: 1 addition & 0 deletions src/Exceptions/Package/PackageErrorCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ class PackageErrorCode extends ErrorCode

protected int $failedToDelete = 1;
protected int $invalidEntity = 2;
protected int $errorCodeNotFound = 3;
}
9 changes: 9 additions & 0 deletions src/Exceptions/Package/PackageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ public static function invalidEntity(string $entity): ValravnException
Response::HTTP_INTERNAL_SERVER_ERROR
);
}

public static function errorCodeNotFound(string $code): ValravnException
{
return self::make(
"Called error code not found. [$code]",
PackageErrorCode::errorCodeNotFound(),
Response::HTTP_INTERNAL_SERVER_ERROR
);
}
}
1 change: 1 addition & 0 deletions src/Facades/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @method static RoutingService name( string $name )
* @method static RoutingService apiResource( string $name, string $controller )
* @method static RoutingService resource( string $name, string $controller )
* @method static RoutingService relations( string $controller, callable $func )
* @method static RoutingService actions( string $controller, callable $func, string $prefix = '-actions' )
Expand Down
16 changes: 15 additions & 1 deletion tests/Core/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Hans\Valravn\Tests\Core\Models;

use Hans\Valravn\Models\Contracts\Filterable;
use Hans\Valravn\Models\ValravnModel;
use Hans\Valravn\Tests\Core\Factories\CategoryFactory;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Category extends ValravnModel
class Category extends ValravnModel implements Filterable
{
use HasFactory;

Expand All @@ -31,4 +32,17 @@ protected static function newFactory()
{
return CategoryFactory::new();
}

/**
* List of attributes that can be filtered.
*
* @return array
*/
public function getFilterableAttributes(): array
{
return [
'id',
'name',
];
}
}
6 changes: 5 additions & 1 deletion tests/Core/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use Hans\Valravn\Models\Contracts\Filterable;
use Hans\Valravn\Models\Contracts\Loadable;
use Hans\Valravn\Models\Traits\Paginatable;
use Hans\Valravn\Models\ValravnModel;
use Hans\Valravn\Tests\Core\Factories\PostFactory;
use Hans\Valravn\Tests\Core\Resources\Category\CategoryCollection;
use Hans\Valravn\Tests\Core\Resources\Comment\CommentCollection;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -15,6 +17,7 @@
class Post extends ValravnModel implements Filterable, Loadable
{
use HasFactory;
use Paginatable;

protected $fillable = [
'title',
Expand Down Expand Up @@ -62,7 +65,8 @@ public function getFilterableAttributes(): array
public function getLoadableRelations(): array
{
return [
'comments' => CommentCollection::class,
'comments' => CommentCollection::class,
'categories' => CategoryCollection::class,
];
}
}
14 changes: 14 additions & 0 deletions tests/Feature/DTOs/BatchUpdateDtoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Hans\Valravn\DTOs\BatchUpdateDto;
use Hans\Valravn\Tests\TestCase;
use Illuminate\Support\Collection;

class BatchUpdateDtoTest extends TestCase
{
Expand Down Expand Up @@ -31,4 +32,17 @@ public function parse(): void
array_values($result->getData()->toArray())
);
}

/**
* @test
*
* @return void
*/
public function parseEmptyData(): void
{
$result = BatchUpdateDto::make([])->getData();

self::assertInstanceOf(Collection::class, $result);
self::assertCount(0, $result);
}
}
14 changes: 14 additions & 0 deletions tests/Feature/DTOs/HasManyDtoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Hans\Valravn\DTOs\HasManyDto;
use Hans\Valravn\Tests\TestCase;
use Illuminate\Support\Collection;

class HasManyDtoTest extends TestCase
{
Expand Down Expand Up @@ -35,4 +36,17 @@ public function parse(): void
array_values($result->getData()->toArray())
);
}

/**
* @test
*
* @return void
*/
public function parseEmptyData(): void
{
$result = HasManyDto::make([])->getData();

self::assertInstanceOf(Collection::class, $result);
self::assertCount(0, $result);
}
}
14 changes: 14 additions & 0 deletions tests/Feature/DTOs/ManyToManyDtoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Hans\Valravn\DTOs\ManyToManyDto;
use Hans\Valravn\Tests\TestCase;
use Illuminate\Support\Collection;

class ManyToManyDtoTest extends TestCase
{
Expand Down Expand Up @@ -140,4 +141,17 @@ public function withValuesForced(): void
$result->toArray()
);
}

/**
* @test
*
* @return void
*/
public function parseEmptyData(): void
{
$result = ManyToManyDto::make([])->getData();

self::assertInstanceOf(Collection::class, $result);
self::assertCount(0, $result);
}
}
14 changes: 14 additions & 0 deletions tests/Feature/DTOs/MorphToDtoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Hans\Valravn\DTOs\MorphToDto;
use Hans\Valravn\Tests\TestCase;
use Illuminate\Support\Collection;

class MorphToDtoTest extends TestCase
{
Expand All @@ -28,4 +29,17 @@ public function parse(): void
$result->getData()->toArray()
);
}

/**
* @test
*
* @return void
*/
public function parseEmptyData(): void
{
$result = MorphToDto::make([])->getData();

self::assertInstanceOf(Collection::class, $result);
self::assertCount(0, $result);
}
}
Loading