added phpunit and composer stuff
This commit is contained in:
parent
3ad68e4078
commit
ef2e25ef19
1
.phpunit.result.cache
Normal file
1
.phpunit.result.cache
Normal file
@ -0,0 +1 @@
|
||||
C:37:"PHPUnit\Runner\DefaultTestResultCache":508:{a:2:{s:7:"defects";a:4:{s:47:"TestUser::testCanBeCreatedFromValidEmailAddress";i:4;s:48:"TestEmail::testCanBeCreatedFromValidEmailAddress";i:4;s:53:"TestEmail::testCannotBeCreatedFromInvalidEmailAddress";i:4;s:32:"TestEmail::testCanBeUsedAsString";i:4;}s:5:"times";a:4:{s:48:"TestEmail::testCanBeCreatedFromValidEmailAddress";d:0.005;s:53:"TestEmail::testCannotBeCreatedFromInvalidEmailAddress";d:0.001;s:32:"TestEmail::testCanBeUsedAsString";d:0;s:47:"TestUser::testCanBeCreatedFromValidEmailAddress";d:0;}}}
|
||||
10
composer.json
Normal file
10
composer.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"dev_mvc/"
|
||||
]
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8"
|
||||
}
|
||||
}
|
||||
1535
composer.lock
generated
Normal file
1535
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
dev_mvc/.phpunit.result.cache
Normal file
1
dev_mvc/.phpunit.result.cache
Normal file
@ -0,0 +1 @@
|
||||
C:30:"PHPUnit\Runner\TestResultCache":44:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:0:{}}}
|
||||
28
dev_mvc/model/forum/Email.php
Normal file
28
dev_mvc/model/forum/Email.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace model\forum;
|
||||
class Email{
|
||||
private $email;
|
||||
private $valid;
|
||||
function __construct($email){
|
||||
$sanitized_email = filter_var($email, FILTER_SANITIZE_EMAIL);
|
||||
|
||||
if(filter_var($sanitized_email, FILTER_VALIDATE_EMAIL)){
|
||||
$this->email = $sanitized_email;
|
||||
$this->valid = true;
|
||||
}
|
||||
else{
|
||||
$this->email = 'invalid';
|
||||
$this->valid = false;
|
||||
}
|
||||
}
|
||||
public function getEmail(){
|
||||
return $this->email;
|
||||
}
|
||||
public function getValid(){
|
||||
return $this->valid;
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
}
|
||||
9
phpunit.xml
Normal file
9
phpunit.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<phpunit bootstrap="vendor\autoload.php">
|
||||
<testsuites>
|
||||
<testsuite name="unit">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
||||
3
tests/unit/Test.php
Normal file
3
tests/unit/Test.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
include_once 'TestEmail.php';
|
||||
include_once 'TestUser.php';
|
||||
30
tests/unit/TestEmail.php
Normal file
30
tests/unit/TestEmail.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use model\forum\Email;
|
||||
final class TestEmail extends TestCase
|
||||
{
|
||||
public function testCanBeCreatedFromValidEmailAddress(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Email::class,
|
||||
new Email('user@example.com')
|
||||
);
|
||||
}
|
||||
|
||||
public function testCannotBeCreatedFromInvalidEmailAddress(): void
|
||||
{
|
||||
$email = new Email('user');
|
||||
$this->assertFalse($email->getValid());
|
||||
$this->assertEquals($email->getEmail(), 'invalid');
|
||||
}
|
||||
|
||||
public function testCanBeUsedAsString(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
'user@example.com',
|
||||
new Email('user@example.com')
|
||||
);
|
||||
}
|
||||
}
|
||||
16
tests/unit/TestUser.php
Normal file
16
tests/unit/TestUser.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use model\forum\User;
|
||||
|
||||
final class TestUser extends TestCase
|
||||
{
|
||||
public function testCanBeCreatedFromValidEmailAddress(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
new User(1, 'andreas', 'andreas@example.com', 'password', '10-04-2019 12:00:00', '10-04-2019 12:00:00', '94.212.253.51', -1, 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user