Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix authored Feb 20, 2024
1 parent ecfe52a commit 85acebe
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
with:
version: "10.5"
php_version: "8.2"
php_extensions: xdebug
php_extensions: intl xdebug
coverage_clover: clover.xml
coverage_text: true
- name: Make code coverage badge
Expand Down
40 changes: 23 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,44 @@ You can install the package via composer:
composer require --dev gammamatrix/playground-test
```

## Configuration

You can publish the config file with:
```bash
php artisan vendor:publish --provider="Playground\Test\ServiceProvider" --tag="playground-config"
```

See the contents of the published config file: [config/playground-test.php](config/playground-test.php)

### Environment Variables

## Configuration
Information on [environment variables is available on the wiki for this package](https://github.com/gammamatrix/playground-test/wiki/Environment-Variables)

All options are disabled by default.
## PHPStan

Enable all options:
Tests at level 9 on:
- `config/`
- `database/`
- `resources/`
- `src/`
- `tests/Feature/`
- `tests/Unit/`

```sh
composer analyse
```
#
# @var bool Allow publishing of the configuration.
#
PLAYGROUND_TEST_PUBLISH_CONFIG=true
#
# @var string A password for testing the application.
#
PLAYGROUND_TEST_PASSWORD=some-password
#
# @var bool The password in PLAYGROUND_TEST_PASSWORD is already encrypted
#
PLAYGROUND_TEST_PASSWORD_ENCRYPTED=false

## Coding Standards

```sh
composer format
```

## Testing
## Tests

The components of this package are meant to assist in testing playground packages under a Laravel installation with PHPUnit.
```sh
composer test
```

## Changelog

Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ parameters:
paths:
- config
- database
- resources
- src
- tests
- resources

excludePaths:
- 'output/*'
Expand Down
17 changes: 16 additions & 1 deletion src/Feature/Models/ModelCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public function verifyRelationshipHasMany(Model $model, string $accessor): void
/**
* Test the model relationships.
*/
public function testVerifyRelationships(): void
public function test_verify_model_relationships(): void
{
$modelClass = $this->getModelClass();

Expand All @@ -534,4 +534,19 @@ public function testVerifyRelationships(): void
// // '$this' => $this,
// ]);
}

public function test_factory_create(): void
{
$instance = null;

$modelClass = $this->getModelClass();
$this->assertNotEmpty($modelClass);

if (is_callable([$modelClass, 'factory'])) {
$instance = $modelClass::factory()->create();
}

$this->assertNotNull($instance);
$this->assertInstanceOf($modelClass, $instance);
}
}
9 changes: 8 additions & 1 deletion src/Models/PlaygroundUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
*/
namespace Playground\Test\Models;

use Playground\Models\Interfaces\WithCreatorInterface;
use Playground\Models\Interfaces\WithModifierInterface;
use Playground\Models\Traits\WithCreator;
use Playground\Models\Traits\WithModifier;
use Playground\Models\User as BaseUser;

/**
* \Playground\Test\Models\PlaygroundUser
*
* This model includes RBAC and DOES NOT support Sanctum.
*/
class PlaygroundUser extends BaseUser
class PlaygroundUser extends BaseUser implements WithCreatorInterface, WithModifierInterface
{
use WithCreator;
use WithModifier;

protected $table = 'users';
}
15 changes: 15 additions & 0 deletions src/Unit/Models/ModelCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,19 @@ public function test_verify_model_relationships(): void
// // '$this' => $this,
// ]);
}

public function test_model_factory_make(): void
{
$instance = null;

$modelClass = $this->getModelClass();
$this->assertNotEmpty($modelClass);

if (is_callable([$modelClass, 'factory'])) {
$instance = $modelClass::factory()->make();
}

$this->assertNotNull($instance);
$this->assertInstanceOf($modelClass, $instance);
}
}
Loading

0 comments on commit 85acebe

Please sign in to comment.