Skip to content

Commit

Permalink
Merge pull request #16 from burrelle/test/UnitTests
Browse files Browse the repository at this point in the history
Add PHP Unit and basic Unit tests
  • Loading branch information
DivineOmega authored Feb 19, 2019
2 parents 144a610 + 26bb683 commit c1636ae
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
.idea
.idea
.phpunit.result.cache
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@
"psr-4": {
"DivineOmega\\LaravelPasswordExposedValidationRule\\": "./src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^8.0"
}
}
46 changes: 46 additions & 0 deletions tests/Unit/PasswordExposedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Tests\Unit;

use DivineOmega\LaravelPasswordExposedValidationRule\PasswordExposed;
use PHPUnit\Framework\TestCase;

class PasswordExposedTest extends TestCase
{
public function setUp() : void
{
$this->passwordExposed = new PasswordExposed();
}

/** @test */
public function defaultMessageIsReturned()
{
$message = $this->passwordExposed->message();
$this->assertEquals('The :attribute has been exposed in a data breach.', $message);
}

/** @test */
public function customMessageCanBeSet()
{
$customMessage = 'Custom message';
$passwordExposedObject = $this->passwordExposed->setMessage($customMessage);
$setMessage = $passwordExposedObject->message();
$this->assertEquals($customMessage, $setMessage);
}

/** @test */
public function passwordFailsValidation()
{
$password = 'password';
$passed = $this->passwordExposed->passes('password', $password);
$this->assertFalse($passed);
}

/** @test */
public function passwordPassesValidation()
{
$password = uniqid();
$passed = $this->passwordExposed->passes('password', $password);
$this->assertTrue($passed);
}
}

0 comments on commit c1636ae

Please sign in to comment.