From 946fbbc5213e43f331113c05d92c74b40aa2d80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Votruba?= Date: Tue, 28 Nov 2017 08:00:13 +0100 Subject: [PATCH] Tests: use PHPUnit (6.4) exception methods (#165) * tests: update to PHPUnit 6.0 with rector * [cs] clean empty docs * composer: bump to PHPUnit 6.4 * tests: use class references over strings * cleanup --- composer.json | 2 +- src/Phpml/Preprocessing/Imputer.php | 4 +-- tests/Phpml/Association/AprioriTest.php | 2 +- .../Classification/MLPClassifierTest.php | 13 +++------ tests/Phpml/Clustering/KMeansTest.php | 5 ++-- .../Phpml/CrossValidation/RandomSplitTest.php | 9 ++---- tests/Phpml/Dataset/ArrayDatasetTest.php | 5 ++-- tests/Phpml/Dataset/CsvDatasetTest.php | 5 ++-- tests/Phpml/Dataset/FilesDatasetTest.php | 5 ++-- .../Phpml/FeatureExtraction/StopWordsTest.php | 5 ++-- tests/Phpml/Math/ComparisonTest.php | 7 ++--- tests/Phpml/Math/Distance/ChebyshevTest.php | 6 ++-- tests/Phpml/Math/Distance/EuclideanTest.php | 6 ++-- tests/Phpml/Math/Distance/ManhattanTest.php | 6 ++-- tests/Phpml/Math/Distance/MinkowskiTest.php | 6 ++-- tests/Phpml/Math/MatrixTest.php | 28 ++++++------------- .../Phpml/Math/Statistic/CorrelationTest.php | 5 ++-- tests/Phpml/Math/Statistic/MeanTest.php | 13 +++------ .../Math/Statistic/StandardDeviationTest.php | 9 ++---- tests/Phpml/Metric/AccuracyTest.php | 6 ++-- tests/Phpml/ModelManagerTest.php | 5 ++-- tests/Phpml/NeuralNetwork/LayerTest.php | 5 ++-- tests/Phpml/Preprocessing/NormalizerTest.php | 5 ++-- .../SupportVectorMachineTest.php | 19 +++++-------- 24 files changed, 64 insertions(+), 117 deletions(-) diff --git a/composer.json b/composer.json index 0563f3f..7b774f2 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.0", + "phpunit/phpunit": "^6.4", "friendsofphp/php-cs-fixer": "^2.4", "symplify/easy-coding-standard": "dev-master as 2.5", "symplify/coding-standard": "dev-master as 2.5", diff --git a/src/Phpml/Preprocessing/Imputer.php b/src/Phpml/Preprocessing/Imputer.php index bd40948..fdf8796 100644 --- a/src/Phpml/Preprocessing/Imputer.php +++ b/src/Phpml/Preprocessing/Imputer.php @@ -28,9 +28,9 @@ class Imputer implements Preprocessor private $axis; /** - * @var + * @var mixed[] */ - private $samples; + private $samples = []; /** * @param mixed $missingValue diff --git a/tests/Phpml/Association/AprioriTest.php b/tests/Phpml/Association/AprioriTest.php index 7b637c9..68456ff 100644 --- a/tests/Phpml/Association/AprioriTest.php +++ b/tests/Phpml/Association/AprioriTest.php @@ -178,7 +178,7 @@ class AprioriTest extends TestCase * * @return mixed */ - public function invoke(&$object, $method, array $params = []) + public function invoke(&$object, string $method, array $params = []) { $reflection = new ReflectionClass(get_class($object)); $method = $reflection->getMethod($method); diff --git a/tests/Phpml/Classification/MLPClassifierTest.php b/tests/Phpml/Classification/MLPClassifierTest.php index 20bc5e1..ef62d06 100644 --- a/tests/Phpml/Classification/MLPClassifierTest.php +++ b/tests/Phpml/Classification/MLPClassifierTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace tests\Phpml\Classification; use Phpml\Classification\MLPClassifier; +use Phpml\Exception\InvalidArgumentException; use Phpml\ModelManager; use Phpml\NeuralNetwork\Node\Neuron; use PHPUnit\Framework\TestCase; @@ -160,19 +161,15 @@ class MLPClassifierTest extends TestCase $this->assertEquals($predicted, $restoredClassifier->predict($testSamples)); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidLayersNumber(): void { + $this->expectException(InvalidArgumentException::class); new MLPClassifier(2, [], [0, 1]); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidPartialTrainingClasses(): void { + $this->expectException(InvalidArgumentException::class); $classifier = new MLPClassifier(2, [2], [0, 1]); $classifier->partialTrain( [[0, 1], [1, 0]], @@ -181,11 +178,9 @@ class MLPClassifierTest extends TestCase ); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidClassesNumber(): void { + $this->expectException(InvalidArgumentException::class); new MLPClassifier(2, [2], [0]); } diff --git a/tests/Phpml/Clustering/KMeansTest.php b/tests/Phpml/Clustering/KMeansTest.php index f453340..d212157 100644 --- a/tests/Phpml/Clustering/KMeansTest.php +++ b/tests/Phpml/Clustering/KMeansTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace tests\Phpml\Clustering; use Phpml\Clustering\KMeans; +use Phpml\Exception\InvalidArgumentException; use PHPUnit\Framework\TestCase; class KMeansTest extends TestCase @@ -51,11 +52,9 @@ class KMeansTest extends TestCase $this->assertCount(4, $clusters); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidClusterNumber(): void { + $this->expectException(InvalidArgumentException::class); new KMeans(0); } } diff --git a/tests/Phpml/CrossValidation/RandomSplitTest.php b/tests/Phpml/CrossValidation/RandomSplitTest.php index 070e36b..8058fd6 100644 --- a/tests/Phpml/CrossValidation/RandomSplitTest.php +++ b/tests/Phpml/CrossValidation/RandomSplitTest.php @@ -6,23 +6,20 @@ namespace tests\Phpml\CrossValidation; use Phpml\CrossValidation\RandomSplit; use Phpml\Dataset\ArrayDataset; +use Phpml\Exception\InvalidArgumentException; use PHPUnit\Framework\TestCase; class RandomSplitTest extends TestCase { - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnToSmallTestSize(): void { + $this->expectException(InvalidArgumentException::class); new RandomSplit(new ArrayDataset([], []), 0); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnToBigTestSize(): void { + $this->expectException(InvalidArgumentException::class); new RandomSplit(new ArrayDataset([], []), 1); } diff --git a/tests/Phpml/Dataset/ArrayDatasetTest.php b/tests/Phpml/Dataset/ArrayDatasetTest.php index 41e037b..e0a6b91 100644 --- a/tests/Phpml/Dataset/ArrayDatasetTest.php +++ b/tests/Phpml/Dataset/ArrayDatasetTest.php @@ -5,15 +5,14 @@ declare(strict_types=1); namespace tests\Phpml\Dataset; use Phpml\Dataset\ArrayDataset; +use Phpml\Exception\InvalidArgumentException; use PHPUnit\Framework\TestCase; class ArrayDatasetTest extends TestCase { - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidArgumentsSize(): void { + $this->expectException(InvalidArgumentException::class); new ArrayDataset([0, 1], [0]); } diff --git a/tests/Phpml/Dataset/CsvDatasetTest.php b/tests/Phpml/Dataset/CsvDatasetTest.php index f5cc851..5049253 100644 --- a/tests/Phpml/Dataset/CsvDatasetTest.php +++ b/tests/Phpml/Dataset/CsvDatasetTest.php @@ -5,15 +5,14 @@ declare(strict_types=1); namespace tests\Phpml\Dataset; use Phpml\Dataset\CsvDataset; +use Phpml\Exception\FileException; use PHPUnit\Framework\TestCase; class CsvDatasetTest extends TestCase { - /** - * @expectedException \Phpml\Exception\FileException - */ public function testThrowExceptionOnMissingFile(): void { + $this->expectException(FileException::class); new CsvDataset('missingFile', 3); } diff --git a/tests/Phpml/Dataset/FilesDatasetTest.php b/tests/Phpml/Dataset/FilesDatasetTest.php index 0592d06..ee08395 100644 --- a/tests/Phpml/Dataset/FilesDatasetTest.php +++ b/tests/Phpml/Dataset/FilesDatasetTest.php @@ -5,15 +5,14 @@ declare(strict_types=1); namespace tests\Phpml\Dataset; use Phpml\Dataset\FilesDataset; +use Phpml\Exception\DatasetException; use PHPUnit\Framework\TestCase; class FilesDatasetTest extends TestCase { - /** - * @expectedException \Phpml\Exception\DatasetException - */ public function testThrowExceptionOnMissingRootFolder(): void { + $this->expectException(DatasetException::class); new FilesDataset('some/not/existed/path'); } diff --git a/tests/Phpml/FeatureExtraction/StopWordsTest.php b/tests/Phpml/FeatureExtraction/StopWordsTest.php index 4b715ef..6d97a23 100644 --- a/tests/Phpml/FeatureExtraction/StopWordsTest.php +++ b/tests/Phpml/FeatureExtraction/StopWordsTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests\Phpml\FeatureExtraction; +use Phpml\Exception\InvalidArgumentException; use Phpml\FeatureExtraction\StopWords; use PHPUnit\Framework\TestCase; @@ -22,11 +23,9 @@ class StopWordsTest extends TestCase $this->assertFalse($stopWords->isStopWord('amet')); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidLanguage(): void { + $this->expectException(InvalidArgumentException::class); StopWords::factory('Lorem'); } diff --git a/tests/Phpml/Math/ComparisonTest.php b/tests/Phpml/Math/ComparisonTest.php index 2c72f5f..ecb58c2 100644 --- a/tests/Phpml/Math/ComparisonTest.php +++ b/tests/Phpml/Math/ComparisonTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests\Phpml\Math; +use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Comparison; use PHPUnit\Framework\TestCase; @@ -22,12 +23,10 @@ class ComparisonTest extends TestCase $this->assertEquals($expected, $result); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - * @expectedExceptionMessage Invalid operator "~=" provided - */ public function testThrowExceptionWhenOperatorIsInvalid(): void { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid operator "~=" provided'); Comparison::compare(1, 1, '~='); } diff --git a/tests/Phpml/Math/Distance/ChebyshevTest.php b/tests/Phpml/Math/Distance/ChebyshevTest.php index 893c000..56d6685 100644 --- a/tests/Phpml/Math/Distance/ChebyshevTest.php +++ b/tests/Phpml/Math/Distance/ChebyshevTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests\Phpml\Metric; +use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Distance\Chebyshev; use PHPUnit\Framework\TestCase; @@ -19,14 +20,11 @@ class ChebyshevTest extends TestCase $this->distanceMetric = new Chebyshev(); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidArguments(): void { + $this->expectException(InvalidArgumentException::class); $a = [0, 1, 2]; $b = [0, 2]; - $this->distanceMetric->distance($a, $b); } diff --git a/tests/Phpml/Math/Distance/EuclideanTest.php b/tests/Phpml/Math/Distance/EuclideanTest.php index 03bf7f3..4acb3d4 100644 --- a/tests/Phpml/Math/Distance/EuclideanTest.php +++ b/tests/Phpml/Math/Distance/EuclideanTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests\Phpml\Metric; +use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Distance\Euclidean; use PHPUnit\Framework\TestCase; @@ -19,14 +20,11 @@ class EuclideanTest extends TestCase $this->distanceMetric = new Euclidean(); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidArguments(): void { + $this->expectException(InvalidArgumentException::class); $a = [0, 1, 2]; $b = [0, 2]; - $this->distanceMetric->distance($a, $b); } diff --git a/tests/Phpml/Math/Distance/ManhattanTest.php b/tests/Phpml/Math/Distance/ManhattanTest.php index 9c20edd..2a05874 100644 --- a/tests/Phpml/Math/Distance/ManhattanTest.php +++ b/tests/Phpml/Math/Distance/ManhattanTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests\Phpml\Metric; +use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Distance\Manhattan; use PHPUnit\Framework\TestCase; @@ -19,14 +20,11 @@ class ManhattanTest extends TestCase $this->distanceMetric = new Manhattan(); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidArguments(): void { + $this->expectException(InvalidArgumentException::class); $a = [0, 1, 2]; $b = [0, 2]; - $this->distanceMetric->distance($a, $b); } diff --git a/tests/Phpml/Math/Distance/MinkowskiTest.php b/tests/Phpml/Math/Distance/MinkowskiTest.php index 81ecd97..a8159d7 100644 --- a/tests/Phpml/Math/Distance/MinkowskiTest.php +++ b/tests/Phpml/Math/Distance/MinkowskiTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests\Phpml\Metric; +use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Distance\Minkowski; use PHPUnit\Framework\TestCase; @@ -19,14 +20,11 @@ class MinkowskiTest extends TestCase $this->distanceMetric = new Minkowski(); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidArguments(): void { + $this->expectException(InvalidArgumentException::class); $a = [0, 1, 2]; $b = [0, 2]; - $this->distanceMetric->distance($a, $b); } diff --git a/tests/Phpml/Math/MatrixTest.php b/tests/Phpml/Math/MatrixTest.php index 8d0e1be..fce83bf 100644 --- a/tests/Phpml/Math/MatrixTest.php +++ b/tests/Phpml/Math/MatrixTest.php @@ -4,16 +4,16 @@ declare(strict_types=1); namespace tests\Phpml\Math; +use Phpml\Exception\InvalidArgumentException; +use Phpml\Exception\MatrixException; use Phpml\Math\Matrix; use PHPUnit\Framework\TestCase; class MatrixTest extends TestCase { - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidMatrixSupplied(): void { + $this->expectException(InvalidArgumentException::class); new Matrix([[1, 2], [3]]); } @@ -29,20 +29,16 @@ class MatrixTest extends TestCase $this->assertEquals($flatArray, $matrix->getColumnValues(0)); } - /** - * @expectedException \Phpml\Exception\MatrixException - */ public function testThrowExceptionOnInvalidColumnNumber(): void { + $this->expectException(MatrixException::class); $matrix = new Matrix([[1, 2, 3], [4, 5, 6]]); $matrix->getColumnValues(4); } - /** - * @expectedException \Phpml\Exception\MatrixException - */ public function testThrowExceptionOnGetDeterminantIfArrayIsNotSquare(): void { + $this->expectException(MatrixException::class); $matrix = new Matrix([[1, 2, 3], [4, 5, 6]]); $matrix->getDeterminant(); } @@ -85,14 +81,11 @@ class MatrixTest extends TestCase $this->assertEquals($transposedMatrix, $matrix->transpose()->toArray()); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnMultiplyWhenInconsistentMatrixSupplied(): void { + $this->expectException(InvalidArgumentException::class); $matrix1 = new Matrix([[1, 2, 3], [4, 5, 6]]); $matrix2 = new Matrix([[3, 2, 1], [6, 5, 4]]); - $matrix1->multiply($matrix2); } @@ -132,26 +125,21 @@ class MatrixTest extends TestCase $this->assertEquals($quotient, $matrix->divideByScalar(2)->toArray()); } - /** - * @expectedException \Phpml\Exception\MatrixException - */ public function testThrowExceptionWhenInverseIfArrayIsNotSquare(): void { + $this->expectException(MatrixException::class); $matrix = new Matrix([[1, 2, 3], [4, 5, 6]]); $matrix->inverse(); } - /** - * @expectedException \Phpml\Exception\MatrixException - */ public function testThrowExceptionWhenInverseIfMatrixIsSingular(): void { + $this->expectException(MatrixException::class); $matrix = new Matrix([ [0, 0, 0], [0, 0, 0], [0, 0, 0], ]); - $matrix->inverse(); } diff --git a/tests/Phpml/Math/Statistic/CorrelationTest.php b/tests/Phpml/Math/Statistic/CorrelationTest.php index 7fd2cec..c091bb2 100644 --- a/tests/Phpml/Math/Statistic/CorrelationTest.php +++ b/tests/Phpml/Math/Statistic/CorrelationTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace test\Phpml\Math\StandardDeviation; +use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Statistic\Correlation; use PHPUnit\Framework\TestCase; @@ -29,11 +30,9 @@ class CorrelationTest extends TestCase $this->assertEquals(0.911, Correlation::pearson($x, $y), '', $delta); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidArgumentsForPearsonCorrelation(): void { + $this->expectException(InvalidArgumentException::class); Correlation::pearson([1, 2, 4], [3, 5]); } } diff --git a/tests/Phpml/Math/Statistic/MeanTest.php b/tests/Phpml/Math/Statistic/MeanTest.php index 86553e0..f19479a 100644 --- a/tests/Phpml/Math/Statistic/MeanTest.php +++ b/tests/Phpml/Math/Statistic/MeanTest.php @@ -4,16 +4,15 @@ declare(strict_types=1); namespace test\Phpml\Math\StandardDeviation; +use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Statistic\Mean; use PHPUnit\Framework\TestCase; class MeanTest extends TestCase { - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testArithmeticThrowExceptionOnEmptyArray(): void { + $this->expectException(InvalidArgumentException::class); Mean::arithmetic([]); } @@ -25,11 +24,9 @@ class MeanTest extends TestCase $this->assertEquals(1.7, Mean::arithmetic([0.5, 0.5, 1.5, 2.5, 3.5]), '', $delta); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testMedianThrowExceptionOnEmptyArray(): void { + $this->expectException(InvalidArgumentException::class); Mean::median([]); } @@ -47,11 +44,9 @@ class MeanTest extends TestCase $this->assertEquals(3.5, Mean::median($numbers)); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testModeThrowExceptionOnEmptyArray(): void { + $this->expectException(InvalidArgumentException::class); Mean::mode([]); } diff --git a/tests/Phpml/Math/Statistic/StandardDeviationTest.php b/tests/Phpml/Math/Statistic/StandardDeviationTest.php index ead67b5..4bc4392 100644 --- a/tests/Phpml/Math/Statistic/StandardDeviationTest.php +++ b/tests/Phpml/Math/Statistic/StandardDeviationTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace test\Phpml\Math\StandardDeviation; +use Phpml\Exception\InvalidArgumentException; use Phpml\Math\Statistic\StandardDeviation; use PHPUnit\Framework\TestCase; @@ -25,19 +26,15 @@ class StandardDeviationTest extends TestCase $this->assertEquals(50989, StandardDeviation::population($population), '', $delta); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnEmptyArrayIfNotSample(): void { + $this->expectException(InvalidArgumentException::class); StandardDeviation::population([], false); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnToSmallArray(): void { + $this->expectException(InvalidArgumentException::class); StandardDeviation::population([1]); } } diff --git a/tests/Phpml/Metric/AccuracyTest.php b/tests/Phpml/Metric/AccuracyTest.php index 885893d..e876da1 100644 --- a/tests/Phpml/Metric/AccuracyTest.php +++ b/tests/Phpml/Metric/AccuracyTest.php @@ -7,20 +7,18 @@ namespace tests\Phpml\Metric; use Phpml\Classification\SVC; use Phpml\CrossValidation\RandomSplit; use Phpml\Dataset\Demo\IrisDataset; +use Phpml\Exception\InvalidArgumentException; use Phpml\Metric\Accuracy; use Phpml\SupportVectorMachine\Kernel; use PHPUnit\Framework\TestCase; class AccuracyTest extends TestCase { - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidArguments(): void { + $this->expectException(InvalidArgumentException::class); $actualLabels = ['a', 'b', 'a', 'b']; $predictedLabels = ['a', 'a']; - Accuracy::score($actualLabels, $predictedLabels); } diff --git a/tests/Phpml/ModelManagerTest.php b/tests/Phpml/ModelManagerTest.php index e44a32a..f47efb7 100644 --- a/tests/Phpml/ModelManagerTest.php +++ b/tests/Phpml/ModelManagerTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests; +use Phpml\Exception\FileException; use Phpml\ModelManager; use Phpml\Regression\LeastSquares; use PHPUnit\Framework\TestCase; @@ -23,11 +24,9 @@ class ModelManagerTest extends TestCase $this->assertEquals($estimator, $restored); } - /** - * @expectedException \Phpml\Exception\FileException - */ public function testRestoreWrongFile(): void { + $this->expectException(FileException::class); $filepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'unexisting'; $modelManager = new ModelManager(); $modelManager->restoreFromFile($filepath); diff --git a/tests/Phpml/NeuralNetwork/LayerTest.php b/tests/Phpml/NeuralNetwork/LayerTest.php index 72d8758..11f5e6a 100644 --- a/tests/Phpml/NeuralNetwork/LayerTest.php +++ b/tests/Phpml/NeuralNetwork/LayerTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests\Phpml\NeuralNetwork; +use Phpml\Exception\InvalidArgumentException; use Phpml\NeuralNetwork\Layer; use Phpml\NeuralNetwork\Node\Bias; use Phpml\NeuralNetwork\Node\Neuron; @@ -39,11 +40,9 @@ class LayerTest extends TestCase } } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - */ public function testThrowExceptionOnInvalidNodeClass(): void { + $this->expectException(InvalidArgumentException::class); new Layer(1, stdClass::class); } diff --git a/tests/Phpml/Preprocessing/NormalizerTest.php b/tests/Phpml/Preprocessing/NormalizerTest.php index 3d5940a..5dfc207 100644 --- a/tests/Phpml/Preprocessing/NormalizerTest.php +++ b/tests/Phpml/Preprocessing/NormalizerTest.php @@ -4,16 +4,15 @@ declare(strict_types=1); namespace tests\Phpml\Preprocessing; +use Phpml\Exception\NormalizerException; use Phpml\Preprocessing\Normalizer; use PHPUnit\Framework\TestCase; class NormalizerTest extends TestCase { - /** - * @expectedException \Phpml\Exception\NormalizerException - */ public function testThrowExceptionOnInvalidNorm(): void { + $this->expectException(NormalizerException::class); new Normalizer(99); } diff --git a/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php b/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php index ebbf99f..59154e3 100644 --- a/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php +++ b/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests\Phpml\SupportVectorMachine; +use Phpml\Exception\InvalidArgumentException; use Phpml\SupportVectorMachine\Kernel; use Phpml\SupportVectorMachine\SupportVectorMachine; use Phpml\SupportVectorMachine\Type; @@ -81,32 +82,26 @@ SV $this->assertEquals('c', $predictions[2]); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - * @expectedExceptionMessage is not writable - */ public function testThrowExceptionWhenVarPathIsNotWritable(): void { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is not writable'); $svm = new SupportVectorMachine(Type::C_SVC, Kernel::RBF); $svm->setVarPath('var-path'); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - * @expectedExceptionMessage does not exist - */ public function testThrowExceptionWhenBinPathDoesNotExist(): void { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('does not exist'); $svm = new SupportVectorMachine(Type::C_SVC, Kernel::RBF); $svm->setBinPath('bin-path'); } - /** - * @expectedException \Phpml\Exception\InvalidArgumentException - * @expectedExceptionMessage not found - */ public function testThrowExceptionWhenFileIsNotFoundInBinPath(): void { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('not found'); $svm = new SupportVectorMachine(Type::C_SVC, Kernel::RBF); $svm->setBinPath('var'); }