Skip to content

Commit

Permalink
bump min php version to 7.3 and small WizardTest.php refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
smajti1 committed Mar 15, 2021
1 parent 1aca218 commit a3d2367
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 37 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM php:8.0-rc-fpm-alpine
FROM php:7.3-fpm-alpine

RUN apk update && apk add --no-cache \
bash \
curl \
git \
shadow
shadow \
$PHPIZE_DEPS

RUN pecl install xdebug-3.0.3 && docker-php-ext-enable xdebug

RUN usermod -u 1000 www-data
RUN chown www-data:www-data /var/www/
Expand Down
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@
],
"homepage": "https://github.com/smajti1/laravel-wizard",
"require": {
"php": "^7.2 || ^8.0",
"illuminate/http": "^6.0 || ^7.0 || ^8.0"
"php": "^7.3 || ^8.0",
"illuminate/http": "^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0"
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"Smajti1\\Laravel\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Smajti1\\LaravelWizard\\Test\\": "tests/"
}
}
}
19 changes: 19 additions & 0 deletions tests/Step/FirstDumpStep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Smajti1\LaravelWizard\Test\Step;

use Illuminate\Http\Request;
use Smajti1\Laravel\Step;

class FirstDumpStep extends Step
{
public static $label = 'First step label';
public static $slug = 'first-step';
public static $view = '';

public function process(Request $request)
{
}
}
19 changes: 19 additions & 0 deletions tests/Step/SecondDumpStep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Smajti1\LaravelWizard\Test\Step;

use Illuminate\Http\Request;
use Smajti1\Laravel\Step;

class SecondDumpStep extends Step
{
public static $label = 'Second step label';
public static $slug = 'second-step';
public static $view = '';

public function process(Request $request)
{
}
}
19 changes: 19 additions & 0 deletions tests/Step/ThirdDumpStep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Smajti1\LaravelWizard\Test\Step;

use Illuminate\Http\Request;
use Smajti1\Laravel\Step;

class ThirdDumpStep extends Step
{
public static $label = 'Third step label';
public static $slug = 'third-step';
public static $view = '';

public function process(Request $request)
{
}
}
68 changes: 36 additions & 32 deletions tests/WizardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,53 @@

declare(strict_types=1);

namespace Smajti1\LaravelWizard\Test;

use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Smajti1\Laravel\Exceptions\StepNotFoundException;
use Smajti1\Laravel\Step;
use Smajti1\Laravel\Wizard;
use Smajti1\LaravelWizard\Test\Step\FirstDumpStep;
use Smajti1\LaravelWizard\Test\Step\SecondDumpStep;
use Smajti1\LaravelWizard\Test\Step\ThirdDumpStep;

class WizardTest extends PHPUnit\Framework\TestCase
class WizardTest extends TestCase
{
protected $sessionKeyName;
protected $wizardFirstStepKey;
protected $steps;
protected $wizard;
protected $firstTestStepClass;
protected $secondTestStepClass;
protected $wizard_reflection;
protected $thirdTestStepClass;
protected $wizardThirdStepKey;

public function __construct()
{
parent::__construct();
$this->firstTestStepClass = $this->createPartialMock(Step::class, ['process',]);
$this->firstTestStepClass::$label = 'First step label';
$this->firstTestStepClass::$slug = 'first-step';
$this->firstTestStepClass::$view = '';

$this->secondTestStepClass = $this->createPartialMock(Step::class, ['process',]);
$this->secondTestStepClass::$label = 'Second step label';
$this->secondTestStepClass::$slug = 'second-step';
$this->secondTestStepClass::$view = '';

$this->thirdTestStepClass = $this->createPartialMock(Step::class, ['process',]);
$this->secondTestStepClass::$label = 'Third step label';
$this->secondTestStepClass::$slug = 'third-step';
$this->secondTestStepClass::$view = '';

$this->wizardFirstStepKey = 'first_step_key';
$this->wizardThirdStepKey = 'step_key_third';
$this->steps = [
$this->wizardFirstStepKey => get_class($this->firstTestStepClass),
get_class($this->secondTestStepClass),
$this->wizardThirdStepKey => get_class($this->thirdTestStepClass),
$this->wizardFirstStepKey => FirstDumpStep::class,
SecondDumpStep::class,
$this->wizardThirdStepKey => ThirdDumpStep::class,
];
$this->sessionKeyName = 'test';
$this->wizard = $this->createPartialMock(Wizard::class, [
'createStepClass',
'lastProcessedIndex',
]);

$this->wizard_reflection = new ReflectionClass(Wizard::class);
}

public function testConstructor(): void
{
$this->wizard->expects(self::exactly(3))
{
$wizard = $this->createPartialMock(Wizard::class, [
'createStepClass',
]);
$wizard->expects(self::exactly(3))
->method('createStepClass');
$this->wizard->__construct($this->steps);
$wizard->__construct($this->steps);
}

public function testConstructorEmptySteps(): void
Expand All @@ -65,6 +57,15 @@ public function testConstructorEmptySteps(): void
$this->wizard->__construct([]);
}

public function testConstructorStepsInDifferentDirection(): void
{
$this->wizard->__construct([SecondDumpStep::class, ThirdDumpStep::class, FirstDumpStep::class]);
$allSteps = $this->wizard->all();
self::assertInstanceOf(SecondDumpStep::class, $allSteps[0]);
self::assertInstanceOf(ThirdDumpStep::class, $allSteps[1]);
self::assertInstanceOf(FirstDumpStep::class, $allSteps[2]);
}

public function testCreateStepClass(): void
{
$testStepClassName = 'TestStepClassName';
Expand Down Expand Up @@ -109,7 +110,7 @@ public function testPrevSlug(): void
$this->wizard->__construct($this->steps);
self::assertNull($this->wizard->prevSlug());
$this->wizard->nextStep();
self::assertEquals($this->firstTestStepClass::$slug, $this->wizard->prevSlug());
self::assertEquals(FirstDumpStep::$slug, $this->wizard->prevSlug());
}

public function testNextStep(): void
Expand All @@ -123,7 +124,7 @@ public function testNextStep(): void
public function testNextSlug(): void
{
$this->wizard->__construct($this->steps);
self::assertEquals($this->secondTestStepClass::$slug, $this->wizard->nextSlug());
self::assertEquals(SecondDumpStep::$slug, $this->wizard->nextSlug());
$this->wizard->nextStep();
$this->wizard->nextStep();
self::assertNull($this->wizard->nextSlug());
Expand All @@ -139,7 +140,7 @@ public function testFirst(): void
{
$this->wizard->__construct($this->steps);
$result = $this->wizard->first();
self::assertEquals($this->firstTestStepClass::$slug, $result::$slug);
self::assertEquals(FirstDumpStep::$slug, $result::$slug);
}

public function testFirstOrLastProcessed(): void
Expand All @@ -151,6 +152,9 @@ public function testFirstOrLastProcessed(): void
$allSteps = $this->wizard->all();
$result = $this->wizard->firstOrLastProcessed();
self::assertEquals($allSteps[1], $result);
self::assertInstanceOf(FirstDumpStep::class, $allSteps[0]);
self::assertInstanceOf(SecondDumpStep::class, $allSteps[1]);
self::assertInstanceOf(ThirdDumpStep::class, $allSteps[2]);
}

public function testLastProcessedIndex(): void
Expand All @@ -175,13 +179,13 @@ public function testWizardTestSteps(): void
{
$this->wizard->__construct($this->steps);
$nextStep = $this->wizard->nextStep();
self::assertEquals($nextStep::$slug, $this->secondTestStepClass::$slug);
self::assertEquals($nextStep::$slug, SecondDumpStep::$slug);

$goBackToPrevStep = $this->wizard->prevStep();
self::assertEquals($goBackToPrevStep::$slug, $this->firstTestStepClass::$slug);
self::assertEquals($goBackToPrevStep::$slug, FirstDumpStep::$slug);

$stepBySlug = $this->wizard->getBySlug($this->secondTestStepClass::$slug);
self::assertEquals($stepBySlug::$slug, $this->secondTestStepClass::$slug);
$stepBySlug = $this->wizard->getBySlug(SecondDumpStep::$slug);
self::assertEquals($stepBySlug::$slug, SecondDumpStep::$slug);
}

}

0 comments on commit a3d2367

Please sign in to comment.