Compare commits
No commits in common. "main" and "f61eea9169e05c00dcf24aee7b96c8f4ff8f2972" have entirely different histories.
main
...
f61eea9169
|
@ -1,3 +1 @@
|
|||
vendor/
|
||||
/.phpunit.result.cache
|
||||
.phpunit.cache/
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
# From https://docs.gitlab.com/ee/ci/examples/php.html
|
||||
image: php:7.4-cli
|
||||
|
||||
before_script:
|
||||
# Install dependencies
|
||||
- bash ci/docker_install.sh > /dev/null
|
||||
|
||||
test:
|
||||
script:
|
||||
- php composer.phar run test:gitlab
|
||||
artifacts:
|
||||
when: always
|
||||
reports:
|
||||
junit: report.xml
|
|
@ -1,8 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/todo-list.iml" filepath="$PROJECT_DIR$/.idea/todo-list.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpTestFrameworkVersionCache">
|
||||
<tools_cache>
|
||||
<tool tool_name="PHPUnit">
|
||||
<cache>
|
||||
<versions>
|
||||
<info id="interpreter-cc25df52-c356-4ba0-a7e8-8584ab3c0c28" version="9.5.9" />
|
||||
</versions>
|
||||
</cache>
|
||||
</tool>
|
||||
</tools_cache>
|
||||
</component>
|
||||
</project>
|
116
.idea/php.xml
116
.idea/php.xml
|
@ -1,116 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpIncludePathManager">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-timer" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-text-template" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-invoker" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-file-iterator" />
|
||||
<path value="$PROJECT_DIR$/vendor/myclabs/deep-copy" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-code-coverage" />
|
||||
<path value="$PROJECT_DIR$/vendor/webmozart/assert" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpspec/prophecy" />
|
||||
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/type" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/diff" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-docblock" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/lines-of-code" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/type-resolver" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/object-enumerator" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/comparator" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/cli-parser" />
|
||||
<path value="$PROJECT_DIR$/vendor/theseer/tokenizer" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/exporter" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/version" />
|
||||
<path value="$PROJECT_DIR$/vendor/composer" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/complexity" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/recursion-context" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/resource-operations" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit-reverse-lookup" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/global-state" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/environment" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/object-reflector" />
|
||||
<path value="$PROJECT_DIR$/vendor/phar-io/version" />
|
||||
<path value="$PROJECT_DIR$/vendor/phar-io/manifest" />
|
||||
<path value="$PROJECT_DIR$/vendor/doctrine/instantiator" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpInterpreters">
|
||||
<interpreters>
|
||||
<interpreter id="cc25df52-c356-4ba0-a7e8-8584ab3c0c28" name="Debian" home="\\wsl$\Debian/usr/bin/php" debugger_id="php.debugger.XDebug">
|
||||
<remote_data INTERPRETER_PATH="/usr/bin/php" HELPERS_PATH="" INITIALIZED="false" VALID="true" RUN_AS_ROOT_VIA_SUDO="false" DISTRIBUTION_ID="Debian" />
|
||||
</interpreter>
|
||||
</interpreters>
|
||||
</component>
|
||||
<component name="PhpInterpretersPhpInfoCache">
|
||||
<phpInfoCache>
|
||||
<interpreter name="Debian">
|
||||
<phpinfo binary_type="PHP" php_cli="/usr/bin/php7.4" path_separator=":" remote_host="172.24.192.1" version="7.4.21">
|
||||
<additional_php_ini>/etc/php/7.4/cli/conf.d/10-opcache.ini, /etc/php/7.4/cli/conf.d/10-pdo.ini, /etc/php/7.4/cli/conf.d/15-xml.ini, /etc/php/7.4/cli/conf.d/20-calendar.ini, /etc/php/7.4/cli/conf.d/20-ctype.ini, /etc/php/7.4/cli/conf.d/20-curl.ini, /etc/php/7.4/cli/conf.d/20-dom.ini, /etc/php/7.4/cli/conf.d/20-exif.ini, /etc/php/7.4/cli/conf.d/20-ffi.ini, /etc/php/7.4/cli/conf.d/20-fileinfo.ini, /etc/php/7.4/cli/conf.d/20-ftp.ini, /etc/php/7.4/cli/conf.d/20-gettext.ini, /etc/php/7.4/cli/conf.d/20-iconv.ini, /etc/php/7.4/cli/conf.d/20-json.ini, /etc/php/7.4/cli/conf.d/20-mbstring.ini, /etc/php/7.4/cli/conf.d/20-phar.ini, /etc/php/7.4/cli/conf.d/20-posix.ini, /etc/php/7.4/cli/conf.d/20-readline.ini, /etc/php/7.4/cli/conf.d/20-shmop.ini, /etc/php/7.4/cli/conf.d/20-simplexml.ini, /etc/php/7.4/cli/conf.d/20-sockets.ini, /etc/php/7.4/cli/conf.d/20-sysvmsg.ini, /etc/php/7.4/cli/conf.d/20-sysvsem.ini, /etc/php/7.4/cli/conf.d/20-sysvshm.ini, /etc/php/7.4/cli/conf.d/20-tokenizer.ini, /etc/php/7.4/cli/conf.d/20-xmlreader.ini, /etc/php/7.4/cli/conf.d/20-xmlwriter.ini, /etc/php/7.4/cli/conf.d/20-xsl.ini, /etc/php/7.4/cli/conf.d/20-zip.ini</additional_php_ini>
|
||||
<configuration_file>/etc/php/7.4/cli/php.ini</configuration_file>
|
||||
<configuration_options>
|
||||
<configuration_option name="include_path" value=".:/usr/share/php" />
|
||||
</configuration_options>
|
||||
<debuggers />
|
||||
<loaded_extensions>
|
||||
<extension name="Core" />
|
||||
<extension name="FFI" />
|
||||
<extension name="PDO" />
|
||||
<extension name="Phar" />
|
||||
<extension name="Reflection" />
|
||||
<extension name="SPL" />
|
||||
<extension name="SimpleXML" />
|
||||
<extension name="Zend OPcache" />
|
||||
<extension name="calendar" />
|
||||
<extension name="ctype" />
|
||||
<extension name="curl" />
|
||||
<extension name="date" />
|
||||
<extension name="dom" />
|
||||
<extension name="exif" />
|
||||
<extension name="fileinfo" />
|
||||
<extension name="filter" />
|
||||
<extension name="ftp" />
|
||||
<extension name="gettext" />
|
||||
<extension name="hash" />
|
||||
<extension name="iconv" />
|
||||
<extension name="json" />
|
||||
<extension name="libxml" />
|
||||
<extension name="mbstring" />
|
||||
<extension name="openssl" />
|
||||
<extension name="pcntl" />
|
||||
<extension name="pcre" />
|
||||
<extension name="posix" />
|
||||
<extension name="readline" />
|
||||
<extension name="session" />
|
||||
<extension name="shmop" />
|
||||
<extension name="sockets" />
|
||||
<extension name="sodium" />
|
||||
<extension name="standard" />
|
||||
<extension name="sysvmsg" />
|
||||
<extension name="sysvsem" />
|
||||
<extension name="sysvshm" />
|
||||
<extension name="tokenizer" />
|
||||
<extension name="xml" />
|
||||
<extension name="xmlreader" />
|
||||
<extension name="xmlwriter" />
|
||||
<extension name="xsl" />
|
||||
<extension name="zip" />
|
||||
<extension name="zlib" />
|
||||
</loaded_extensions>
|
||||
</phpinfo>
|
||||
</interpreter>
|
||||
</phpInfoCache>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.0">
|
||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||
</component>
|
||||
<component name="PhpUnit">
|
||||
<phpunit_settings>
|
||||
<PhpUnitSettings custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" />
|
||||
</phpunit_settings>
|
||||
</component>
|
||||
</project>
|
|
@ -1,47 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="MMK2410\MyTodoList\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-timer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-text-template" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-invoker" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-file-iterator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/myclabs/deep-copy" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-code-coverage" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpspec/prophecy" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/nikic/php-parser" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/type" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/diff" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-docblock" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/lines-of-code" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/type-resolver" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/object-enumerator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpdocumentor/reflection-common" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/comparator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/code-unit" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/cli-parser" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/theseer/tokenizer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/exporter" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/version" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/complexity" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/resource-operations" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/code-unit-reverse-lookup" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/global-state" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/environment" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/object-reflector" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phar-io/version" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phar-io/manifest" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/instantiator" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,7 +0,0 @@
|
|||
pipeline:
|
||||
test:
|
||||
image: php:7.4-cli
|
||||
pull: true
|
||||
commands:
|
||||
- bash ci/docker_install.sh > /dev/null
|
||||
- php composer.phar run test
|
7
LICENSE
7
LICENSE
|
@ -1,7 +0,0 @@
|
|||
Copyright © 2021 Marcel Kapfer <opensource@mmk2410.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
README.md
10
README.md
|
@ -1,10 +0,0 @@
|
|||
# My ToDo List
|
||||
|
||||
My todo list is a PHP project that I develop for training PHP.
|
||||
|
||||
## Development
|
||||
|
||||
Currently, I use PHP 7.4 (maybe I will switch to PHP 8 soon) and follow a TDD approach.
|
||||
The program will store its data in a MySQL database that will be connected and accessed using the Doctrine DBAL.
|
||||
Goal of the PHP application is a RESTful API build with some web framework like Symphony or Laravel.
|
||||
This will be used by a frontend that won't be powered by PHP but (as of now) TypeScript and some fancy JavaScript framework like Angular, React or Vue.
|
|
@ -1,23 +0,0 @@
|
|||
#!/bin/bash
|
||||
# From https://docs.gitlab.com/ee/ci/examples/php.html
|
||||
|
||||
# We need to install dependencies only for Docker
|
||||
[[ ! -e /.dockerenv ]] && exit 0
|
||||
|
||||
set -xe
|
||||
|
||||
# Install git (the php image doesn't have it) which is required by composer
|
||||
apt-get update -yqq
|
||||
apt-get install git wget unzip -yqq
|
||||
|
||||
# Install & enable Xdebug for code coverage reports
|
||||
pecl install xdebug
|
||||
docker-php-ext-enable xdebug
|
||||
|
||||
# Install composer dependencies
|
||||
wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig
|
||||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||
php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
|
||||
php composer-setup.php
|
||||
php -r "unlink('composer-setup.php'); unlink('installer.sig');"
|
||||
php composer.phar install
|
|
@ -4,18 +4,5 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9"
|
||||
},
|
||||
"scripts": {
|
||||
"test": [
|
||||
"phpunit --configuration phpunit.xml"
|
||||
],
|
||||
"test:coverage": [
|
||||
"@putenv XDEBUG_MODE=coverage",
|
||||
"phpunit --configuration phpunit.xml --coverage-text"
|
||||
],
|
||||
"test:gitlab": [
|
||||
"@putenv XDEBUG_MODE=coverage",
|
||||
"phpunit --configuration phpunit.xml --log-junit report.xml --coverage-text --colors=never"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
22
phpunit.xml
22
phpunit.xml
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
cacheResultFile=".phpunit.cache/test-results"
|
||||
executionOrder="depends,defects"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
verbose="true">
|
||||
<testsuites>
|
||||
<testsuite name="default">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<coverage cacheDirectory=".phpunit.cache/code-coverage"
|
||||
processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
</phpunit>
|
|
@ -0,0 +1,33 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace MMK2410\MyTodoList;
|
||||
|
||||
final class Email
|
||||
{
|
||||
private $email;
|
||||
|
||||
private function __construct(string $email)
|
||||
{
|
||||
$this->ensureIsValidEmail($email);
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public static function fromString(string $email): self
|
||||
{
|
||||
return new self($email);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
private function ensureIsValidEmail(string $email): void
|
||||
{
|
||||
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf("%s is not a valid email address", $email)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace MMK2410\MyTodoList;
|
||||
|
||||
class IdManager
|
||||
{
|
||||
private static array $ids = array();
|
||||
|
||||
public static function generateID(string $classname): int
|
||||
{
|
||||
if (!array_key_exists($classname, self::$ids)) {
|
||||
self::$ids[$classname] = 0;
|
||||
return 0;
|
||||
} else {
|
||||
return ++self::$ids[$classname];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCurrentId(string $classname)
|
||||
{
|
||||
if (!array_key_exists($classname, self::$ids)) {
|
||||
return 0;
|
||||
} else {
|
||||
return self::$ids[$classname];
|
||||
}
|
||||
}
|
||||
}
|
77
src/Todo.php
77
src/Todo.php
|
@ -1,77 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace MMK2410\MyTodoList;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
|
||||
class Todo
|
||||
{
|
||||
const ExceptionMsgInvalidTitle = "Empty task title not allowed";
|
||||
const ExceptionMsgInvalidState = "Invalid state tried to set.";
|
||||
|
||||
private string $title;
|
||||
private string $state;
|
||||
private bool $important;
|
||||
private int $id;
|
||||
|
||||
public function __construct(string $title, bool $important = false)
|
||||
{
|
||||
$this->validateTitle($title);
|
||||
$this->id = IdManager::generateID(self::class);
|
||||
$this->title = $title;
|
||||
$this->state = TodoStates::Todo;
|
||||
$this->important = $important;
|
||||
}
|
||||
|
||||
public function getID(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): void
|
||||
{
|
||||
$this->validateTitle($title);
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
public function setState(string $state): void
|
||||
{
|
||||
$this->validateState($state);
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
public function getImportant(): bool {
|
||||
return $this->important;
|
||||
}
|
||||
|
||||
public function setImportant(): void {
|
||||
$this->important = true;
|
||||
}
|
||||
|
||||
private function validateTitle(string $title): void
|
||||
{
|
||||
if (empty($title)) {
|
||||
throw new InvalidArgumentException(self::ExceptionMsgInvalidTitle);
|
||||
}
|
||||
}
|
||||
|
||||
private function validateState(string $state): void
|
||||
{
|
||||
$reflect = new ReflectionClass(TodoStates::class);
|
||||
$constantFound = $reflect->getConstant($state);
|
||||
if ($constantFound === FALSE) {
|
||||
throw new InvalidArgumentException(self::ExceptionMsgInvalidState);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MMK2410\MyTodoList;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class TodoList
|
||||
{
|
||||
const ExceptionMsgTodoNotFound = "Could not find todo with given ID";
|
||||
|
||||
private string $name;
|
||||
private array $todos;
|
||||
private int $id;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->id = IdManager::generateID(self::class);
|
||||
$this->name = $name;
|
||||
$this->todos = array();
|
||||
}
|
||||
|
||||
public function getID(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function addTodo(Todo $todo): void
|
||||
{
|
||||
$this->todos[] = $todo;
|
||||
}
|
||||
|
||||
public function getTodos(): array
|
||||
{
|
||||
return $this->todos;
|
||||
}
|
||||
|
||||
public function getTodoById(int $id): Todo
|
||||
{
|
||||
foreach ($this->todos as $todo) {
|
||||
if ($todo->getID() == $id) {
|
||||
return $todo;
|
||||
}
|
||||
}
|
||||
throw new InvalidArgumentException(self::ExceptionMsgTodoNotFound);
|
||||
}
|
||||
|
||||
public function deleteTodoById(int $id): void
|
||||
{
|
||||
foreach ($this->todos as $key => $todo) {
|
||||
if ($todo->getID() == $id) {
|
||||
unset($this->todos[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MMK2410\MyTodoList;
|
||||
|
||||
abstract class TodoStates
|
||||
{
|
||||
const Todo = "Todo";
|
||||
const Done = "Done";
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php declare(strict_types=1);
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use MMK2410\MyTodoList\Email;
|
||||
|
||||
final class EmailTest extends TestCase
|
||||
{
|
||||
private $email = 'user@example.com';
|
||||
|
||||
public function testCanBeCreatedFromValidEmailAddress(): void {
|
||||
$this->assertInstanceOf(
|
||||
Email::class,
|
||||
Email::fromString($this->email)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCannotBeCreatedFromInvalidEmailAddress(): void {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Email::fromString('invalid');
|
||||
}
|
||||
|
||||
public function testCanBeUsedAsString(): void {
|
||||
$this->assertEquals(
|
||||
$this->email,
|
||||
Email::fromString($this->email)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
|
||||
use MMK2410\MyTodoList\IdManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class IdManagerTest extends TestCase
|
||||
{
|
||||
public function testGenerateTwoIds(): void
|
||||
{
|
||||
$id1 = IdManager::generateID(IdManagerTest::class . "::testGenerateTwoIds");
|
||||
$id2 = IdManager::generateID(IdManagerTest::class . "::testGenerateTwoIds");
|
||||
self::assertNotEquals(
|
||||
$id1,
|
||||
$id2,
|
||||
"ID 1 '$id1' and ID 2 '$id2' are equal, but the shouldn't."
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetCurrentId(): void
|
||||
{
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
IdManager::generateID(IdManagerTest::class . "::testGetCurrentId()");
|
||||
}
|
||||
$currentId = IdManager::getCurrentId(IdManagerTest::class . "::testGetCurrentId()");
|
||||
self::assertEquals(
|
||||
2,
|
||||
$currentId,
|
||||
"Expected current ID to be '2', but got '$currentId'"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use MMK2410\MyTodoList\Todo;
|
||||
use MMK2410\MyTodoList\TodoList;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TodoListTest extends TestCase
|
||||
{
|
||||
public function testCreateTodoList(): void {
|
||||
$todolist1 = new TodoList("My Todo List");
|
||||
$todolist2 = new TodoList("My Todo List");
|
||||
$this->assertNotEquals(
|
||||
$todolist1->getID(),
|
||||
$todolist2->getID(),
|
||||
"Expected todo lists to have different UIDs but they have the same."
|
||||
);
|
||||
}
|
||||
|
||||
public function testTodoListHasName(): void
|
||||
{
|
||||
$name = "My Todo List";
|
||||
$todolist = new TodoList($name);
|
||||
$this->assertEquals(
|
||||
$name,
|
||||
$todolist->getName(),
|
||||
"Created todo list with name '$name', but it has name '{$todolist->getName()}'",
|
||||
);
|
||||
}
|
||||
|
||||
public function testChangeTodoListName(): void
|
||||
{
|
||||
$todolist = new TodoList("Old name");
|
||||
$new_todolist_name = "New name";
|
||||
$todolist->setName($new_todolist_name);
|
||||
$this->assertEquals(
|
||||
$new_todolist_name,
|
||||
$todolist->getName(),
|
||||
"Renamed todo list to '$new_todolist_name', but its name is '{$todolist->getName()}'"
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetEmptyTodos(): void
|
||||
{
|
||||
$todolist = new TodoList("Some list");
|
||||
$todoAmount = sizeof($todolist->getTodos());
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$todoAmount,
|
||||
"Got wrong amount of todos. Expected 0, got $todoAmount"
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetTodos(): void
|
||||
{
|
||||
$todolist = new TodoList("Some list");
|
||||
for ($i = 1; $i < 3; $i++) {
|
||||
$todolist->addTodo(new Todo("Some todo"));
|
||||
}
|
||||
$i--; // Decrement $i for using it in the assertion
|
||||
$todoAmount = sizeof($todolist->getTodos());
|
||||
$this->assertEquals(
|
||||
$i,
|
||||
$todoAmount,
|
||||
"Got wrong amount of todos. Expected $i, got $todoAmount"
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddTodo(): void
|
||||
{
|
||||
$todolist = new TodoList("Some list");
|
||||
$todo = new Todo("Some todo");
|
||||
$todolist->addTodo($todo);
|
||||
$id_todo = $todo->getID();
|
||||
$id_todo_from_list = $todolist->getTodos()[0]->getID();
|
||||
$this->assertEquals(
|
||||
$id_todo,
|
||||
$id_todo_from_list,
|
||||
"Got wrong todo. Expected ID $id_todo, got $id_todo_from_list"
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetTodoById(): void
|
||||
{
|
||||
$todolist = new TodoList("Some list");
|
||||
$todo = new Todo("Some todo");
|
||||
$todolist->addTodo($todo);
|
||||
$id_todo = $todo->getID();
|
||||
$id_todo_from_list = $todolist->getTodoById($id_todo)->getID();
|
||||
$this->assertEquals(
|
||||
$id_todo,
|
||||
$id_todo_from_list,
|
||||
"Got wrong todo. Expected ID $id_todo, got $id_todo_from_list"
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetNonExistentTodoById(): void
|
||||
{
|
||||
$todolist = new TodoList("Some list");
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage(TodoList::ExceptionMsgTodoNotFound);
|
||||
$todolist->getTodoById(-1);
|
||||
}
|
||||
|
||||
public function testDeleteTodoById(): void
|
||||
{
|
||||
$todolist = new TodoList("Some list");
|
||||
$todo = new Todo("Delete me");
|
||||
$todolist->addTodo($todo);
|
||||
$todolist->deleteTodoById($todo->getID());
|
||||
$amountTodos = sizeof($todolist->getTodos());
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$amountTodos,
|
||||
"Expected not todos to be left, but there are/is $amountTodos left"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use MMK2410\MyTodoList\Todo;
|
||||
use MMK2410\MyTodoList\TodoStates;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TodoTest extends TestCase
|
||||
{
|
||||
public function testCreateTodo(): void {
|
||||
$todo1 = new Todo("Some title");
|
||||
$todo2 = new Todo("Some title");
|
||||
$this->assertNotEquals(
|
||||
$todo1->getID(),
|
||||
$todo2->getID(),
|
||||
"Expected todos to have different UIDs but they have the same."
|
||||
);
|
||||
}
|
||||
|
||||
public function testTodoHasTitle(): void
|
||||
{
|
||||
$title = "Some task";
|
||||
$todo = new Todo($title);
|
||||
$this->assertEquals(
|
||||
$title,
|
||||
$todo->getTitle(),
|
||||
"Expected title '$title', but got '{$todo->getTitle()}'"
|
||||
);
|
||||
}
|
||||
|
||||
public function testDontCreateEmptyTodo(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage(Todo::ExceptionMsgInvalidTitle);
|
||||
new Todo("");
|
||||
}
|
||||
|
||||
public function testUpdateTitle(): void
|
||||
{
|
||||
$anotherTitle = "Another title";
|
||||
$todo = new Todo("Some title");
|
||||
$todo->setTitle($anotherTitle);
|
||||
$this->assertEquals(
|
||||
$anotherTitle,
|
||||
$todo->getTitle(),
|
||||
"Expected new title $anotherTitle, but got {$todo->getTitle()}"
|
||||
);
|
||||
}
|
||||
|
||||
public function testNewTodoState(): void
|
||||
{
|
||||
$todo = new Todo("stub");
|
||||
$this->assertEquals(
|
||||
TodoStates::Todo,
|
||||
$todo->getStatus(),
|
||||
"Expected todo state 'Todo', but got {$todo->getStatus()}"
|
||||
);
|
||||
}
|
||||
|
||||
public function testChangeTodoState(): void
|
||||
{
|
||||
$todo = new Todo("stub");
|
||||
$todo->setState(TodoStates::Done);
|
||||
$this->assertEquals(
|
||||
TodoStates::Done,
|
||||
$todo->getStatus(),
|
||||
"Expected todo state 'Done', but got {$todo->getStatus()}"
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetBogusTodoState(): void
|
||||
{
|
||||
$todo = new Todo("stub");
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage(Todo::ExceptionMsgInvalidState);
|
||||
$todo->setState("bogus");
|
||||
}
|
||||
|
||||
public function testCreateImportantTodo(): void
|
||||
{
|
||||
$todo = new Todo("Some title", true);
|
||||
$this->assertTrue(
|
||||
$todo->getImportant(),
|
||||
"Todo created as important, but it is not"
|
||||
);
|
||||
}
|
||||
|
||||
public function testMakeTodoImportant(): void {
|
||||
$todo = new Todo("Some title");
|
||||
$todo->setImportant();
|
||||
$this->assertTrue(
|
||||
$todo->getImportant(),
|
||||
"Todo changed to important, but it is not"
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue