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

Update composer dependencies and prepare for L9 support #21

Merged
merged 3 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
build
composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
docs
vendor
coverage.clover
.idea/

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
],
"require": {
"php": "^7.2|^8.0",
"illuminate/support": "~5.6|^6.0|^7.0|^8.0"
"illuminate/support": "~5.6|^6.0|^7.0|^8.0|^9.0"
},
"require-dev": {
"orchestra/testbench": "^3.6|^4.0|^5.0|^6.0",
"orchestra/testbench": "^3.6|^4.0|^5.0|^6.0|^7.0",
"phpunit/phpunit": "^7.0|^8.2|^9.0"
},
"autoload": {
Expand All @@ -36,10 +36,11 @@
}
},
"suggest": {
"binary-cats/laravel-lob-webhooks": "Handle Lob.com webhooks in your Laravel application",
"binary-cats/laravel-mailgun-webhooks": "Handle Mailgun webhooks in your Laravel application"
},
"scripts": {
"test": "vendor/bin/phpunit --color=always",
"test": "XDEBUG_MODE=coverage vendor/bin/phpunit --color=always ",
"check": [
"php-cs-fixer fix --ansi --dry-run --diff src",
"php-cs-fixer fix --ansi --dry-run --diff tests",
Expand Down
26 changes: 14 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand All @@ -8,22 +9,23 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false">
stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Binary Cats Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
16 changes: 12 additions & 4 deletions src/Contracts/SkuOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@

namespace BinaryCats\Sku\Contracts;

/**
* @property-read string[] $source
* @property-read string $field
* @property-read bool $unit
* @property-read string $separator
* @property-read bool $generateOnCreate
* @property-read bool $generateOnUpdate
*/
interface SkuOptions
{
/**
* Create a new instance of the class, with standard settings.
*
* @return new instance
* @return $this
*/
public static function make(): self;

/**
* Set the source field.
*
* @param mixed $field
* @param string[]|string $field
* @return $this
*/
public function from($field): self;

/**
* Set the destination field.
*
* @param mixed $field
* @param string $field
* @return $this
*/
public function target(string $field): self;

/**
* Set unique flag.
*
* @param boll $value
* @param bool $value
* @return $this
*/
public function forceUnique(bool $value): self;
Expand Down
6 changes: 2 additions & 4 deletions tests/CustomGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

class CustomGeneratorTest extends TestCase
{
/**
* @test
*/
public function is_can_use_custom_generator()
/** @test */
public function it_can_use_custom_generator()
{
config()->set('laravel-sku.default.generate_on_create', true);

Expand Down
18 changes: 18 additions & 0 deletions tests/SkuGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace BinaryCats\Sku\Tests;

use BinaryCats\Sku\Concerns\SkuGenerator;

class SkuGeneratorTest extends TestCase
{
/** @test */
public function it_will_convert_to_json()
{
$model = DummyModel::make();

$generator = new SkuGenerator($model);

$this->assertJson($generator->toJson());
}
}
50 changes: 50 additions & 0 deletions tests/SkuOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace BinaryCats\Sku\Tests;

use BinaryCats\Sku\Concerns\SkuOptions;
use BinaryCats\Sku\Contracts\SkuOptions as SkuOptionsContract;
use BinaryCats\Sku\Exceptions\SkuException;

class SkuOptionsTest extends TestCase
{
/** @test */
public function it_can_create_sku_options_statically()
{
$options = SkuOptions::make();

$this->assertInstanceOf(SkuOptionsContract::class, $options);
}

/** @test */
public function it_will_throw_exception_on_missing_property()
{
$this->expectException(SkuException::class);

SkuOptions::make()->garbage_property_that_doesnt_exist;
}

/** @test */
public function it_can_set_properties_via_methods()
{
$options = SkuOptions::make();

$options->from('foo');
$this->assertEquals(['foo'], $options->source);

$options->from(['foo', 'bar']);
$this->assertEquals(['foo', 'bar'], $options->source);

$options->target('baz');
$this->assertEquals('baz', $options->field);

$options->forceUnique(true);
$this->assertTrue($options->unique);

$options->forceUnique(false);
$this->assertFalse($options->unique);

$options->allowDuplicates();
$this->assertFalse($options->unique);
}
}
28 changes: 6 additions & 22 deletions tests/SkuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

class SkuTest extends TestCase
{
/**
* @test
*/
/** @test */
public function it_will_have_sku_on_create()
{
$one = DummyModelFactory::new()->create();
Expand All @@ -17,9 +15,7 @@ public function it_will_have_sku_on_create()
$this->assertIsString($one->sku);
}

/**
* @test
*/
/** @test */
public function it_will_miss_sku_on_create_if_configured()
{
config()->set('laravel-sku.default.generate_on_create', false);
Expand All @@ -31,29 +27,21 @@ public function it_will_miss_sku_on_create_if_configured()
$this->assertNull($value);
}

/**
* @test
*/
/** @test */
public function it_will_reset_sku_on_update()
{
$one = DummyModelFactory::new()->create();

$sku = $one->sku;

$one->forceFill(
[
'name' => Str::random(),
]
)->save();
$one->forceFill(['name' => Str::random()])->save();

$this->assertFalse(Str::is($one->sku, $sku));
$this->assertIsString($sku);
$this->assertIsString($one->sku);
}

/**
* @test
*/
/** @test */
public function it_will_preserve_sku_on_update_when_configured()
{
config()->set('laravel-sku.default.generate_on_update', false);
Expand All @@ -62,11 +50,7 @@ public function it_will_preserve_sku_on_update_when_configured()

$sku = $one->sku;

$one->forceFill(
[
'name' => Str::random(),
]
)->save();
$one->forceFill(['name' => Str::random()])->save();

$this->assertTrue(Str::is($one->sku, $sku));
$this->assertIsString($sku);
Expand Down