Skip to content

Commit

Permalink
fix PSR12 styles for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Jun 29, 2021
1 parent 8e53911 commit 3725061
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 99 deletions.
28 changes: 12 additions & 16 deletions tests/DrawSampleTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace HiFolks\RandoPhp\Tests;


use HiFolks\RandoPhp\Draw;
use PHPUnit\Framework\TestCase;

Expand All @@ -12,8 +10,8 @@ class DrawSampleTest extends TestCase
/** @test */
public function random_extract()
{
$array=[1,2,3,4,5,6,7,8,9];
$count=5;
$array = [1,2,3,4,5,6,7,8,9];
$count = 5;
$sample = Draw::sample($array)->count($count)->extract();
$this->assertIsArray($sample);
$this->assertSame($count, count($sample));
Expand Down Expand Up @@ -56,18 +54,17 @@ public function random_extract_keys_with_empty_stuff()
/** @test */
public function random_extract_implode()
{
$array=[1,2,3,4,5,6,7,8,9];
$count=5;
$array = [1,2,3,4,5,6,7,8,9];
$count = 5;
$sample = Draw::sample($array)->count($count)->implode()->extract();
$this->assertIsString($sample);

}

/** @test */
public function random_extract_preservekeys()
{
$array=range(1,100);
$count=5;
$array = range(1, 100);
$count = 5;
$sample = Draw::sample($array)->count($count)->preserveKeys()->extract();
$this->assertIsArray($sample);
$this->assertSame($count, count($sample), "Check extract count is correct");
Expand All @@ -76,17 +73,17 @@ public function random_extract_preservekeys()
/** @test */
public function random_snap()
{
$array=["testa" => "Testa", "croce" => "Croce"];
$array = ["testa" => "Testa", "croce" => "Croce"];

$sample = Draw::sample($array)->snap();
$this->assertIsString($sample, "Element is a string");
$this->assertContains($sample,["Testa", "Croce"], "Element is in Array");
$this->assertContains($sample, ["Testa", "Croce"], "Element is in Array");

$sample = Draw::sample($array)->snapKey();
$this->assertIsString($sample, "Element is a string");
$this->assertContains($sample,["testa", "croce"], "Element is in Array");
$this->assertContains($sample, ["testa", "croce"], "Element is in Array");

$array=[
$array = [
"first" => ["This", "is", "First"],
"second" => ["This" , "is", "Second" ]
];
Expand All @@ -95,11 +92,10 @@ public function random_snap()

$sample = Draw::sample($array)->snapKey();
$this->assertIsString($sample, "Element is a string");
$this->assertContains($sample,["first", "second"], "Element is a valid key");
$this->assertContains($sample, ["first", "second"], "Element is a valid key");

$array=[10,11,12,13];
$array = [10,11,12,13];
$sample = Draw::sample($array)->snap();
$this->assertIsInt($sample, "Element is an Integer");
}

}
1 change: 0 additions & 1 deletion tests/LoadModelsWithMagicFunctionsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace HiFolks\RandoPhp\Tests;

use HiFolks\RandoPhp\Exceptions\ModelNotFoundException;
Expand Down
2 changes: 0 additions & 2 deletions tests/RandomBooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ public function random_boolean()
$this->assertLessThanOrEqual(1, $boolean, "Check max number - boolean");
$this->assertIsBool($boolean, "Check is boolean");
}


}
8 changes: 2 additions & 6 deletions tests/RandomByteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public function random_byte()
$byte = Randomize::byte()->generate();
$this->assertIsString($byte, "Is String");

foreach (range(1,32) as $len) {
foreach (range(1, 32) as $len) {
$byte = Randomize::byte()->length($len)->generate();
$this->assertSame($len*2, strlen($byte), "Check length ". $len);
$this->assertSame($len * 2, strlen($byte), "Check length " . $len);
}
$catch = false;
try {
Expand All @@ -25,9 +25,5 @@ public function random_byte()
$this->assertIsString($e->getMessage(), "Message Error");
}
$this->assertSame(true, $catch, "Exception catch");


}


}
13 changes: 4 additions & 9 deletions tests/RandomCharTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public function it_generates_char()
$this->assertIsString($char, "Is String");
$this->assertSame(1, strlen($char), "Is 1 char");
$this->assertTrue(ctype_alpha($char), "Check for alphabetic character");
$this->assertTrue(($char==='a' or $char ==='b'), "Check for alphabetic character: " . $char );


$this->assertTrue(($char === 'a' or $char === 'b'), "Check for alphabetic character: " . $char);
}

/** @test */
Expand Down Expand Up @@ -119,15 +117,12 @@ public function it_generates_customchars()
$this->assertIsString($char, "Is String");
$this->assertSame(1, strlen($char), "Is 1 char");

$this->assertTrue(in_array(ord($char), $array), "--Check for right char: -". $char."-" . $string."++++++");
$this->assertTrue(in_array(ord($char), $array), "--Check for right char: -" . $char . "-" . $string . "++++++");

$array = ['a', 'B', 'z'];

$char = Randomize::char()->addArrayChars($array)->alpha()->generate();
$this->assertIsString($char, "Is String");
$this->assertSame(1, strlen($char), "Is 1 char: -". $char."-");


}

$this->assertSame(1, strlen($char), "Is 1 char: -" . $char . "-");
}
}
13 changes: 5 additions & 8 deletions tests/RandomDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,24 @@ public function random_datetime_min_max()
public function random_datetime_format()
{
$year = Randomize::datetime()->min('01-10-2020')->max('10-10-2020')->format("Y")->generate();
$this->assertEquals("2020", $year );
$this->assertEquals("2020", $year);
}

/** @test */
public function random_datetime_range_format()
{
$month = Randomize::datetime()->range('01-10-2020', '30-10-2020')->format("m")->generate();
$this->assertSame("10", $month , "Extracting the right month");
$this->assertSame("10", $month, "Extracting the right month");

$month = Randomize::datetime()->range('01-10-2020', '09-10-2020')->format("m")->generate();
$this->assertSame("10", $month , "Extracting the right month 2");
$this->assertSame("10", $month, "Extracting the right month 2");

$month = Randomize::datetime()->range('01-10-2020 00:00:00', '01-10-2020 12:00:00')->format("m")->generate();
$this->assertSame("10", $month , "Extracting the right month 2");
$this->assertSame("10", $month, "Extracting the right month 2");
$day = Randomize::datetime()->range('01-10-2020 00:00:00', '01-10-2020 12:00:00')->format("d")->generate();
$this->assertSame("01", $day , "Extracting the right day");
$this->assertSame("01", $day, "Extracting the right day");
$year = Randomize::datetime()->range('01-01-2020', 'now')->format("Y")->generate();
$this->assertIsString($year, "Generated Y is a string");
$this->assertSame(strlen($year), 4, "Generated Y is 4 chars");


}

}
21 changes: 7 additions & 14 deletions tests/RandomFloatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function random_float_min_max_types_validation(): void

try {
Randomize::float()->min("string");
}
catch (InvalidArgumentException $exception) {
} catch (InvalidArgumentException $exception) {
$catched = true;
$this->assertEquals("The min argument must be either an integer or a float.", $exception->getMessage());
}
Expand All @@ -44,8 +43,7 @@ public function random_float_min_max_types_validation(): void

try {
Randomize::float()->max("string");
}
catch (InvalidArgumentException $exception) {
} catch (InvalidArgumentException $exception) {
$catched = true;
$this->assertEquals("The max argument must be either an integer or a float.", $exception->getMessage());
}
Expand All @@ -56,8 +54,7 @@ public function random_float_min_max_types_validation(): void

try {
Randomize::float()->range(0, "string");
}
catch (InvalidArgumentException $exception) {
} catch (InvalidArgumentException $exception) {
$catched = true;
$this->assertEquals("The max argument must be either an integer or a float.", $exception->getMessage());
}
Expand All @@ -68,8 +65,7 @@ public function random_float_min_max_types_validation(): void

try {
Randomize::float()->range("string", 0);
}
catch (InvalidArgumentException $exception) {
} catch (InvalidArgumentException $exception) {
$catched = true;
$this->assertEquals("The min argument must be either an integer or a float.", $exception->getMessage());
}
Expand All @@ -80,8 +76,7 @@ public function random_float_min_max_types_validation(): void

try {
Randomize::float()->range("string", "another string");
}
catch (InvalidArgumentException $exception) {
} catch (InvalidArgumentException $exception) {
$catched = true;
$this->assertEquals("The min argument must be either an integer or a float.", $exception->getMessage());
}
Expand Down Expand Up @@ -119,8 +114,7 @@ public function random_float_min_max_decimals(): void

try {
$number = Randomize::float()->min(10)->max(10)->decimals(-5)->generate();
}
catch (InvalidArgumentException $exception) {
} catch (InvalidArgumentException $exception) {
$this->assertEquals("The number of decimals cannot be negative.", $exception->getMessage());
$catched = true;
}
Expand All @@ -132,8 +126,7 @@ public function random_float_min_max_decimals(): void

try {
$number = Randomize::float()->min(10)->max(1)->decimals(1)->generate();
}
catch (LogicException $exception) {
} catch (LogicException $exception) {
$this->assertEquals("The specified max is <= than the specified min.", $exception->getMessage());
$catched = true;
}
Expand Down
17 changes: 5 additions & 12 deletions tests/RandomIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ public function random_integer()
$this->assertGreaterThanOrEqual(24, $number, "Check min number");
$this->assertLessThanOrEqual(26, $number, "Check max number");
$this->assertIsInt($number, "Check is integer");


}
/** @test */
public function random_integer_min_max()
{
$min=90;
$max=95;
$min = 90;
$max = 95;
$number = Randomize::integer()->min($min)->max($max)->generate();
$this->assertGreaterThanOrEqual($min, $number, "Check min number");
$this->assertLessThanOrEqual($max, $number, "Check max number");
Expand All @@ -43,16 +41,14 @@ public function random_integer_min_max()
$this->assertGreaterThanOrEqual($min, $number, "Check min number generated via range");
$this->assertLessThanOrEqual($max, $number, "Check max number generated via range");
$this->assertIsInt($number, "Check is integer generated via range");


}

/** @test */
public function random_integer_min_max_wrong()
{
$min=50;
$max=30;
$catch=false;
$min = 50;
$max = 30;
$catch = false;
try {
Randomize::integer()->min($min)->max($max)->generate();
} catch (Exception $e) {
Expand All @@ -61,10 +57,7 @@ public function random_integer_min_max_wrong()
} catch (Error $e) {
$catch = true;
$this->assertIsString($e->getMessage(), "Message Error");

}
$this->assertSame(true, $catch, "Exception catch");
}


}
Loading

0 comments on commit 3725061

Please sign in to comment.