Skip to content

Commit

Permalink
code maintenance
Browse files Browse the repository at this point in the history
- fixed phpunit deprecations
- added strict mode to tests and some important places
- added some test coverage
- better readme for local dev
  • Loading branch information
yurii-github committed Oct 7, 2024
1 parent 93d92aa commit a542606
Show file tree
Hide file tree
Showing 42 changed files with 294 additions and 167 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ If you have enabled synchronization application will sync changes to your filesy

To import books into the library you have to drop your books to library folder you've set in configuration and then on *Import* tab press "Import Books".
It will import all books from file system that are not in database yet.

# Development

To configure tests' run you can create local env file `tests/local_test_env.php` with content like below
```
<?php
putenv('DB_TYPE=sqlite_memory'); // sqlite_memory | sqlite | mysql
putenv('DB_DBNAME=my_library_test2');
putenv('DB_LOGIN=my_library_test');
putenv('DB_PASSWORD=my_library_test_pass');
```
By default, `sqlite_memory` is used as database. See `tests/bootstrap.php` for more details.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="false"
displayDetailsOnPhpunitDeprecations="false"
displayDetailsOnPhpunitDeprecations="true"
cacheDirectory=".phpunit.cache"
>
<coverage>
Expand Down
6 changes: 3 additions & 3 deletions src/Actions/Api/Book/Category/ListAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -49,4 +49,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res

return $this->asJSON($gridQuery->paginate(['guid', 'title', 'marker']));
}
}
}
8 changes: 4 additions & 4 deletions src/Actions/Api/Book/Category/ManageAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,7 +36,7 @@
class ManageAction extends AbstractApiAction
{
use WithValidateTrait;

protected Translator $translator;
protected Manager $db;

Expand Down Expand Up @@ -128,4 +128,4 @@ protected function addCategory(array $post): Category

return $category;
}
}
}
6 changes: 3 additions & 3 deletions src/Actions/Api/Book/ListAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -47,4 +47,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res

return $this->asJSON($gridQuery->paginate($columns));
}
}
}
6 changes: 3 additions & 3 deletions src/Actions/Api/Book/ManageAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -119,4 +119,4 @@ protected function addBook(array $post): Book
return $book;
}

}
}
12 changes: 4 additions & 8 deletions src/Actions/Api/Config/CheckFilesAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -29,11 +29,7 @@

class CheckFilesAction extends AbstractApiAction
{
/**
* @var Configuration
*/
protected $config;

protected Configuration $config;

public function __construct(ContainerInterface $container)
{
Expand All @@ -58,4 +54,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
return $this->asJSON($data);
}

}
}
6 changes: 3 additions & 3 deletions src/Actions/Api/Config/ClearBooksWithoutFilesAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -45,4 +45,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
return $this->asJSON($deletedBooks);
}

}
}
6 changes: 3 additions & 3 deletions src/Actions/Api/Config/CountBooksWithoutFilesAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,4 +36,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
return $this->asJSON($count);
}

}
}
7 changes: 3 additions & 4 deletions src/Actions/Api/Config/DoImportFilesAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,7 +30,6 @@

class DoImportFilesAction extends AbstractApiAction
{

public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
{
$addFilenames = Arr::get($request->getParsedBody(), 'post', []);
Expand All @@ -55,4 +54,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
return $this->asJSON($message);
}

}
}
11 changes: 4 additions & 7 deletions src/Actions/Api/Config/DoImportNewCoverFromPdfAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,10 +31,7 @@

class DoImportNewCoverFromPdfAction extends AbstractApiAction
{
/**
* @var CoverExtractor
*/
protected $extractor;
protected CoverExtractor $extractor;

public function __construct(ContainerInterface $container)
{
Expand Down Expand Up @@ -62,4 +59,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
return $this->asJSON(['data' => $addedBooks, 'result' => true, 'error' => null]);
}

}
}
6 changes: 3 additions & 3 deletions src/Actions/Api/Config/GetBooksWithoutCoverAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,4 +38,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res

return $this->asJSON($books);
}
}
}
11 changes: 4 additions & 7 deletions src/Actions/Api/Config/GetImportFilesAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -29,10 +29,7 @@

class GetImportFilesAction extends AbstractApiAction
{
/**
* @var Configuration
*/
protected $config;
protected Configuration $config;

public function __construct(ContainerInterface $container)
{
Expand All @@ -51,4 +48,4 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
return $this->asJSON($arr_fs_only);
}

}
}
9 changes: 4 additions & 5 deletions src/Actions/Api/Config/UpdateAction.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);
/*
* My Book Library
*
* Copyright (C) 2014-2021 Yurii K.
* Copyright (C) 2014-2024 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,8 +30,7 @@

class UpdateAction extends AbstractApiAction
{
/** @var Configuration */
protected $config;
protected Configuration $config;

public function __construct(ContainerInterface $container)
{
Expand Down Expand Up @@ -66,4 +65,4 @@ protected function validate($field, $value)
}
}
}
}
}
19 changes: 7 additions & 12 deletions src/Models/BookFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,20 @@ class BookFile
protected string $filename;
protected string $extension;
protected Configuration $config;


public function __construct(string $filename)
{
$this->filename = $filename;
$this->extension = pathinfo($filename, PATHINFO_EXTENSION);
$this->config = Container::getInstance()->get(Configuration::class);

if ($this->extension === null) {
throw new \Exception("File '$filename' MUST contain extension!");
}
}

public function getFilename(): string
{
return $this->filename;
}

public function getExtension(): string
{
return $this->extension;
Expand All @@ -55,19 +51,18 @@ public function getFilepath(): string
{
return $this->config->getFilepath($this->filename);
}

public function delete(): bool
{
if (!$this->exists()) {
return false;
}

return unlink($this->getFilepath());
}

public function exists(): bool
{
return file_exists($this->getFilepath());
}
}

4 changes: 2 additions & 2 deletions tests/Constraints/CountInDatabase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace Illuminate\Testing\Constraints;

Expand Down Expand Up @@ -80,4 +80,4 @@ public function toString($options = 0): string
{
return (new ReflectionClass($this))->name;
}
}
}
4 changes: 2 additions & 2 deletions tests/Constraints/HasInDatabase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace Illuminate\Testing\Constraints;

Expand Down Expand Up @@ -117,4 +117,4 @@ public function toString($options = 0): string

return json_encode($output ?? [], $options);
}
}
}
4 changes: 2 additions & 2 deletions tests/Constraints/InteractsWithDatabase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace Illuminate\Testing;

Expand Down Expand Up @@ -166,4 +166,4 @@ public function seed($class = 'Database\\Seeders\\DatabaseSeeder')

return $this;
}
}
}
Loading

0 comments on commit a542606

Please sign in to comment.