Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmypuckett committed Apr 9, 2020
2 parents d645344 + b58e81c commit 4907082
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ matrix:
- php: 7.3
- php: 7.3
env: SETUP=lowest
- php: 7.4
- php: 7.4
env: SETUP=lowest

sudo: false

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We solely use [Laravel](https://www.laravel.com) for our applications, so this p
| Branch | Status | Coverage | Code Quality |
| ------ | :----: | :------: | :----------: |
| Develop | [![Build Status](https://travis-ci.org/spinen/laravel-formio.svg?branch=develop)](https://travis-ci.org/spinen/laravel-formio) | [![Code Coverage](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=develop) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=develop) |
| Master | [![Build Status](https://travis-ci.org/spinen/laravel-formio.svg?branch=master)](https://travis-ci.org/spinen/laravel-formio) | [![Code Coverage](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=develop) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=master) |
| Master | [![Build Status](https://travis-ci.org/spinen/laravel-formio.svg?branch=master)](https://travis-ci.org/spinen/laravel-formio) | [![Code Coverage](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=master) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-formio/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-formio/?branch=master) |

## Installation

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
1.0.0
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
"ext-json": "*",
"firebase/php-jwt": "^5.0",
"guzzlehttp/guzzle": "^6.3",
"illuminate/database": "~5.5|~6",
"illuminate/http": "~5.5|~6",
"illuminate/routing": "~5.5|~6",
"illuminate/database": "~5.5|~6|~7",
"illuminate/http": "~5.5|~6|~7",
"illuminate/routing": "~5.5|~6|~7",
"nesbot/carbon": "~1.2|~2",
"vlucas/phpdotenv": "^3.6"
"vlucas/phpdotenv": "^3.6|^4.0"
},
"require-dev": {
"illuminate/auth": "~5.5|~6",
"mockery/mockery": "^1",
"phpunit/phpunit": "~7.0.1|~8.0",
"psy/psysh": "^0.9.9",
"illuminate/auth": "~5.5|~6|~7",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^8.4|^9.0",
"psy/psysh": "^0.10",
"symfony/thanks": "^1.1"
},
"suggest": {
"illuminate/auth": "Required to sync registered users (~5.5|~6)."
"illuminate/auth": "Required to sync registered users (~5.5|~6|~7)."
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">

Expand Down Expand Up @@ -49,7 +49,6 @@
showOnlySummary="true"
showUncoveredFiles="false"/>
<log type="coverage-clover" target="build/phpunit/logs/clover.xml"/>
<log type="json" target="./build/phpunit/logs/logfile.json"/>
<log type="junit" target="./build/phpunit/logs/junit.xml"/>
</logging>
</phpunit>
25 changes: 23 additions & 2 deletions src/Concerns/HasForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Spinen\Formio\Concerns;

use Illuminate\Container\Container;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Support\Facades\Crypt;

/**
Expand All @@ -22,7 +24,8 @@ public function getFormioPasswordAttribute()
{
return is_null($this->attributes['formio_password'] ?? null)
? null
: Crypt::decrypt($this->attributes['formio_password']);
: $this->resolveEncrypter()
->decrypt($this->attributes['formio_password']);
}

/**
Expand Down Expand Up @@ -62,13 +65,31 @@ public function initializeHasFormsTrait()
$this->hidden[] = 'formio_password';
}

/**
* Resolve the encrypter from the IoC
*
* We are staying away from the Crypt facade, so that we can support PHP 7.4 with Laravel 5.x
*
* TODO: Remove this when dropping support of Laravel 5.5
*
* @return Encrypter
*/
protected function resolveEncrypter()
{
return Container::getInstance()
->make(Encrypter::class);
}

/**
* Mutator for FormioPassword.
*
* @param string $formio_password
*/
public function setFormioPasswordAttribute($formio_password)
{
$this->attributes['formio_password'] = is_null($formio_password) ? null : Crypt::encrypt($formio_password);
$this->attributes['formio_password'] = is_null($formio_password)
? null
: $this->resolveEncrypter()
->encrypt($formio_password);
}
}
17 changes: 15 additions & 2 deletions src/Http/Resources/FormioJwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@

namespace Spinen\Formio\Http\Resources;

// NOTE: Extending "Resource" instead of "JsonResource" to be compatible with Laravel 5.5
use Illuminate\Http\Resources\Json\Resource as JsonResource;
//use Illuminate\Http\Resources\Json\JsonResource;

// TODO: When dropping support of Laravel 5.5, remove this if/else
if (class_exists('Illuminate\Http\Resources\Json\JsonResource')) {
class JsonResource extends \Illuminate\Http\Resources\Json\JsonResource
{

}
} else {
// NOTE: Only here to support Laravel 5.5
class JsonResource extends \Illuminate\Http\Resources\Json\Resource
{

}
}

class FormioJwt extends JsonResource
{
Expand Down
15 changes: 11 additions & 4 deletions src/Listeners/AddToFormio.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
namespace Spinen\Formio\Listeners;

use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Config;
use Spinen\Formio\Client as Formio;
use Spinen\Formio\Exceptions\UserException;

class AddToFormio implements ShouldQueue
{
/**
* @var Config
*/
protected $config;

/**
* Formio client instance
*
Expand All @@ -20,10 +25,12 @@ class AddToFormio implements ShouldQueue
/**
* Create the event listener.
*
* @param Config $config
* @param Formio $formio
*/
public function __construct(Formio $formio)
public function __construct(Config $config, Formio $formio)
{
$this->config = $config;
$this->formio = $formio;
}

Expand All @@ -37,7 +44,7 @@ public function __construct(Formio $formio)
*/
public function handle(Registered $event)
{
if (Config::get('formio.user.sync')) {
if ($this->config->get('formio.user.sync')) {
$this->formio->addUser($event->user);
}
}
Expand All @@ -51,6 +58,6 @@ public function handle(Registered $event)
*/
public function shouldQueue(Registered $event)
{
return Config::get('formio.user.sync');
return $this->config->get('formio.user.sync');
}
}
43 changes: 28 additions & 15 deletions tests/Concerns/HasFormsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

namespace Spinen\Formio\Concerns;

use Illuminate\Support\Facades\Crypt;
use Illuminate\Container\Container;
use Illuminate\Contracts\Encryption\Encrypter;
use Mockery;
use Mockery\Mock;
use ReflectionClass;
use Spinen\Formio\Concerns\Stubs\User;
use Spinen\Formio\TestCase;

class HasFormsTest extends TestCase
{
/**
* @var Mock
*/
protected $encrypter_mock;

/**
* @var User
*/
Expand All @@ -17,6 +25,11 @@ class HasFormsTest extends TestCase
protected function setUp(): void
{
$this->trait = new User();

$this->encrypter_mock = Mockery::mock(Encrypter::class);

Container::getInstance()
->instance(Encrypter::class, $this->encrypter_mock);
}

/**
Expand Down Expand Up @@ -46,10 +59,10 @@ public function it_set_fillable_and_hidden_to_have_formio_password()
*/
public function it_encrypts_formio_password()
{
Crypt::shouldReceive('encrypt')
->once()
->withArgs(['password'])
->andReturn('encrypted password');
$this->encrypter_mock->shouldReceive('encrypt')
->once()
->withArgs(['password'])
->andReturn('encrypted password');

$this->trait->setFormioPasswordAttribute('password');

Expand All @@ -61,9 +74,9 @@ public function it_encrypts_formio_password()
*/
public function it_does_not_encrypt_a_null_formio_password()
{
Crypt::shouldReceive('encrypt')
->never()
->withAnyArgs();
$this->encrypter_mock->shouldReceive('encrypt')
->never()
->withAnyArgs();

$this->trait->setFormioPasswordAttribute(null);

Expand All @@ -75,10 +88,10 @@ public function it_does_not_encrypt_a_null_formio_password()
*/
public function it_dencrypts_formio_password()
{
Crypt::shouldReceive('decrypt')
->once()
->withArgs(['encrypted password'])
->andReturn('password');
$this->encrypter_mock->shouldReceive('decrypt')
->once()
->withArgs(['encrypted password'])
->andReturn('password');

$this->trait->attributes['formio_password'] = 'encrypted password';

Expand All @@ -90,9 +103,9 @@ public function it_dencrypts_formio_password()
*/
public function it_does_not_dencrypt_a_null_formio_password()
{
Crypt::shouldReceive('decrypt')
->never()
->withAnyArgs();
$this->encrypter_mock->shouldReceive('decrypt')
->never()
->withAnyArgs();

$this->trait->attributes['formio_password'] = null;

Expand Down
42 changes: 24 additions & 18 deletions tests/Listeners/AddToFormioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Spinen\Formio\Listeners;

use Illuminate\Auth\Events\Registered;
use Illuminate\Support\Facades\Config;
use Illuminate\Contracts\Config\Repository as Config;
use Mockery;
use Mockery\Mock;
use Spinen\Formio\Client;
Expand All @@ -17,6 +17,11 @@ class AddToFormioTest extends TestCase
*/
protected $client_mock;

/**
* @var Mock
*/
protected $config_mock;

/**
* @var AddToFormio
*/
Expand All @@ -35,12 +40,13 @@ class AddToFormioTest extends TestCase
protected function setUp(): void
{
$this->client_mock = Mockery::mock(Client::class);
$this->config_mock = Mockery::mock(Config::class);
$this->registered_mock = Mockery::mock(Registered::class);
$this->user_mock = Mockery::mock(FormioUser::class);

$this->registered_mock->user = $this->user_mock;

$this->listener = new AddToFormio($this->client_mock);
$this->listener = new AddToFormio($this->config_mock, $this->client_mock);
}

/**
Expand All @@ -56,10 +62,10 @@ public function it_can_be_constructed()
*/
public function it_adds_user_to_formio_when_sync_is_configured_true()
{
Config::shouldReceive('get')
->once()
->with('formio.user.sync')
->andReturnTrue();
$this->config_mock->shouldReceive('get')
->once()
->with('formio.user.sync')
->andReturnTrue();

$this->client_mock->shouldReceive('addUser')
->once()
Expand All @@ -74,10 +80,10 @@ public function it_adds_user_to_formio_when_sync_is_configured_true()
*/
public function it_does_not_adds_user_to_formio_when_sync_is_configured_false()
{
Config::shouldReceive('get')
->once()
->with('formio.user.sync')
->andReturnFalse();
$this->config_mock->shouldReceive('get')
->once()
->with('formio.user.sync')
->andReturnFalse();

$this->client_mock->shouldReceive('addUser')
->never()
Expand All @@ -91,10 +97,10 @@ public function it_does_not_adds_user_to_formio_when_sync_is_configured_false()
*/
public function it_will_queue_job_if_sync_is_configured_true()
{
Config::shouldReceive('get')
->once()
->with('formio.user.sync')
->andReturnTrue();
$this->config_mock->shouldReceive('get')
->once()
->with('formio.user.sync')
->andReturnTrue();

$this->assertTrue($this->listener->shouldQueue($this->registered_mock));
}
Expand All @@ -104,10 +110,10 @@ public function it_will_queue_job_if_sync_is_configured_true()
*/
public function it_will_not_queue_job_if_sync_is_configured_false()
{
Config::shouldReceive('get')
->once()
->with('formio.user.sync')
->andReturnFalse();
$this->config_mock->shouldReceive('get')
->once()
->with('formio.user.sync')
->andReturnFalse();

$this->assertFalse($this->listener->shouldQueue($this->registered_mock));
}
Expand Down

0 comments on commit 4907082

Please sign in to comment.