Skip to content

Commit

Permalink
8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
railken committed Mar 28, 2024
1 parent 6ae6f00 commit 206cb1c
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 69 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: 7.2
php-version: 8.3
extension-csv: mbstring, dom, fileinfo, mysql, zip
coverage: xdebug #optional
- name: Get composer cache directory
Expand All @@ -24,8 +24,9 @@ jobs:
- name: Install Composer dependencies
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
composer global require amethyst/cli
composer require --dev phpstan/phpstan
- name: Test Quality
run: |
export PATH="$HOME/.composer/vendor/bin:$PATH"
amethyst test:phpstan --verbose
export PATH="$HOME/.composer/vendor/bin:$PATH"
./vendor/bin/phpstan analyse --level=0 src
./vendor/bin/phpstan analyse --level=0 tests
15 changes: 10 additions & 5 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: 8.3
extension-csv: mbstring, dom, fileinfo, mysql, zip
coverage: xdebug #optional
- name: Install Composer dependencies
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
composer global require amethyst/cli
composer require --dev friendsofphp/php-cs-fixer
- name: Run fix:style
run: |
export PATH="$HOME/.composer/vendor/bin:$PATH"
amethyst fix:style --verbose
./vendor/bin/php-cs-fixer fix src
./vendor/bin/php-cs-fixer fix tests
- uses: stefanzweifel/git-auto-commit-action@v2.1.0
with:
commit_message: Apply style changes
branch: ${{ github.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

23 changes: 12 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
DB_DATABASE: laravel
DB_USERNAME: root
DB_PASSWORD: password
BROADCAST_DRIVER: log
BROADCAST_DRIVER: log
services:
mysql:
image: mysql:5.7
Expand All @@ -27,17 +27,19 @@ jobs:
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
ports:
- 6379/tcp
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4']
laravel: ['5.8.*', '6.*', '7.*', '8.*']
exclude:
- php: '7.2'
laravel: '8.*'
php: ['8.2', '8.3']
laravel: ['9.*', '10.*']
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
Expand All @@ -49,13 +51,12 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Install Composer dependencies
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
composer require --dev amethyst/cli
composer require --dev "laravel/framework:${{ matrix.laravel }}" --no-update;
composer require --dev "laravel/framework:${{ matrix.laravel }}" --no-update
composer update --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Prepare the application
run: |
php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Test
run: vendor/bin/amethyst test:phpunit --verbose
run: ./vendor/bin/phpunit --coverage-text --coverage-clover=build/logs/clover.xml
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
vendor/
var/
\.php_cs\.cache
build/
\.env
composer\.lock
build/
phpunit\.xml

.phpunit.result.cache
phpunit.xml
.php-cs-fixer.cache
.phpunit.cache/test-results
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# amethyst-attribute

[![Action Status](https://github.com/amethyst-php/attribute/workflows/Test/badge.svg)](https://github.com/amethyst-php/attribute/actions)

[![Action Status](https://github.com/amethyst-php/attribute/workflows/Test/badge.svg)](https://github.com/amethyst-php/attribute/actions)./vendor
[Amethyst](https://github.com/amethyst-php/amethyst) package.

# Requirements

PHP 7.1 and later.
PHP 7.2 and later.

## Installation

Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"keywords": ["laravel", "amethyst", "amethyst-attribute-schema", "attribute-schema"],
"license": "MIT",
"require": {
"php": ">=7.2",
"amethyst/core": "0.2.*",
"amethyst/relation-schema": "0.2.*",
"php": ">=8.2",
"amethyst/core": "0.3.*",
"amethyst/relation-schema": "0.3.*",
"doctrine/dbal": "^2.9"
},
"require-dev": {
"phpunit/phpunit": "*",
"orchestra/testbench": "*",
"amethyst/foo": "0.2.*"
"amethyst/foo": "0.3.*"
},
"autoload": {
"psr-4" : {
Expand Down
20 changes: 6 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
</php>
Expand Down
12 changes: 9 additions & 3 deletions src/Observers/AttributeSchemaObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public function updating(AttributeSchema $attributeSchema, bool $onChange = true

$arguments = $attributeSchema->getResolver()->getDatabaseArguments();

print_r($method);

$column = $table->$method(...$arguments);

$attributeSchema->getResolver()->callDatabaseOptions($column);
Expand Down Expand Up @@ -223,12 +225,16 @@ public function convertAttributeOptionsToRelationPayload(AttributeSchema $attrib
}
}

if (!empty($payload->ownerKey)) {
$obj['ownerKey'] = $payload->ownerKey;
}

if (!empty($payload->relationKey)) {
$obj['foreignKey'] = $payload->relationKey;
$obj['keyName'] = $payload->relationKey;
}

if (!empty($payload->ownerKey)) {
$obj['ownerKey'] = $payload->ownerKey;
if ($attributeSchema->schema === 'MorphTo') {
$obj['keyId'] = $attributeSchema->name;
}

return Yaml::dump($obj);
Expand Down
3 changes: 1 addition & 2 deletions tests/BaseTest.php → tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amethyst\Tests;

abstract class BaseTest extends \Orchestra\Testbench\TestCase
abstract class BaseTestCase extends \Orchestra\Testbench\TestCase
{
/**
* Setup the test environment.
Expand All @@ -14,7 +14,6 @@ public function setUp(): void
$this->artisan('migrate:fresh');

app('amethyst.attribute-schema')->boot();
app('amethyst.relation-schema')->boot();
app('eloquent.mapper')->boot();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaBelongsToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Amethyst\Managers\FooManager;
use Symfony\Component\Yaml\Yaml;

class AttributeSchemaBelongsToTest extends AttributeSchemaCommonTest
class AttributeSchemaBelongsToTest extends AttributeSchemaCommonTestCase
{
public function testBasicBelongsTo()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use Amethyst\Managers\AttributeSchemaManager;
use Amethyst\Managers\FooManager;
use Amethyst\Models\Foo;
use Amethyst\Tests\BaseTest;
use Amethyst\Tests\BaseTestCase;

abstract class AttributeSchemaCommonTest extends BaseTest
abstract class AttributeSchemaCommonTestCase extends BaseTestCase
{
public function resetFields()
{
Expand All @@ -32,7 +32,7 @@ public function commonField($name, $type, $valid = [], $invalid = [], $options =
foreach ($valid as $v) {
$parameters = FooFaker::make()->parameters();
$parameters->add(is_array($v) ? $v : [$name => $v]);

$foo = $fooManager->createOrFail($parameters)->getResource();
$foo->save();

Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaDataNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amethyst\Tests\Managers;

class AttributeSchemaDataNameTest extends AttributeSchemaCommonTest
class AttributeSchemaDataNameTest extends AttributeSchemaCommonTestCase
{
public function testBasicDate()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amethyst\Tests\Managers;

class AttributeSchemaDateTest extends AttributeSchemaCommonTest
class AttributeSchemaDateTest extends AttributeSchemaCommonTestCase
{
public function testBasicDate()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amethyst\Tests\Managers;

class AttributeSchemaDateTimeTest extends AttributeSchemaCommonTest
class AttributeSchemaDateTimeTest extends AttributeSchemaCommonTestCase
{
public function testBasicDateTime()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amethyst\Tests\Managers;

class AttributeSchemaEmailTest extends AttributeSchemaCommonTest
class AttributeSchemaEmailTest extends AttributeSchemaCommonTestCase
{
public function testBasicEmail()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\Yaml\Yaml;

class AttributeSchemaEnumTest extends AttributeSchemaCommonTest
class AttributeSchemaEnumTest extends AttributeSchemaCommonTestCase
{
public function testBasicEnum()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaLongTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amethyst\Tests\Managers;

class AttributeSchemaLongTextTest extends AttributeSchemaCommonTest
class AttributeSchemaLongTextTest extends AttributeSchemaCommonTestCase
{
public function testBasicLongText()
{
Expand Down
9 changes: 7 additions & 2 deletions tests/Managers/AttributeSchemaMorphToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
namespace Amethyst\Tests\Managers;

use Symfony\Component\Yaml\Yaml;
use Amethyst\Managers\FooManager;
use Amethyst\Fakers\FooFaker;

class AttributeSchemaMorphToTest extends AttributeSchemaCommonTest
class AttributeSchemaMorphToTest extends AttributeSchemaCommonTestCase
{
public function testBasicMorphTo()
{
$this->resetFields();

$foos = $this->commonField('target_key', 'DataName', ['foo'], ['invalidName']);

$fooManager = new FooManager();
$foo = $fooManager->createOrFail(FooFaker::make()->parameters())->getResource();

$this->commonField('target_id', 'MorphTo', [['target_key' => 'foo', 'target_id' => $foos[0]->id]], [999], Yaml::dump([
$this->commonField('target_id', 'MorphTo', [['target_key' => 'foo', 'target_id' => $foo->id]], [999], Yaml::dump([
'relationName' => 'target',
'relationKey' => 'target_key',
]));
Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amethyst\Tests\Managers;

class AttributeSchemaNumberTest extends AttributeSchemaCommonTest
class AttributeSchemaNumberTest extends AttributeSchemaCommonTestCase
{
public function testBasicNumber()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaRequiredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Amethyst\Managers\AttributeSchemaManager;
use Amethyst\Managers\FooManager;

class AttributeSchemaRequiredTest extends AttributeSchemaCommonTest
class AttributeSchemaRequiredTest extends AttributeSchemaCommonTestCase
{
public function testRequired()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Managers/AttributeSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Amethyst\Fakers\AttributeSchemaFaker;
use Amethyst\Managers\AttributeSchemaManager;
use Amethyst\Tests\BaseTest;
use Amethyst\Tests\BaseTestCase;
use Railken\Lem\Support\Testing\TestableBaseTrait;

class AttributeSchemaTest extends BaseTest
class AttributeSchemaTest extends BaseTestCase
{
use TestableBaseTrait;

Expand Down
2 changes: 1 addition & 1 deletion tests/Managers/AttributeSchemaTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amethyst\Tests\Managers;

class AttributeSchemaTextTest extends AttributeSchemaCommonTest
class AttributeSchemaTextTest extends AttributeSchemaCommonTestCase
{
public function testBasicText()
{
Expand Down

0 comments on commit 206cb1c

Please sign in to comment.