<commit_before><?php

declare(strict_types=1);

/**
 * @testCase
 */

namespace stekycz\Cronner\tests\Tasks;

use stekycz\Cronner\Tasks\Parameters;
use stekycz\Cronner\tests\objects\TestObject;
use Tester\Assert;

require_once(__DIR__ . "/../bootstrap.php");

class ParametersParsingTest extends \TestCase
{

	/**
	 * @var object
	 */
	private $object;

	protected function setUp()
	{
		parent::setUp();
		$this->object = new TestObject();
	}

	/**
	 * @dataProvider dataProviderParse
	 * @param array $expected
	 * @param string $methodName
	 */
	public function testParsesTaskSettings(array $expected, string $methodName)
	{
		if (!(new \Nette\Reflection\ClassType($this->object))->hasMethod($methodName)) {
			Assert::fail('Tested class does not have method "' . $methodName . '".');

			return;
		}

		Assert::same($expected, Parameters::parseParameters((new \Nette\Reflection\ClassType($this->object))->getMethod($methodName)));
	}

	public function dataProviderParse() : array
	{
		return [
			[
				[
					Parameters::TASK => 'E-mail notifications',
					Parameters::PERIOD => '5 minutes',
					Parameters::DAYS => NULL,
					Parameters::TIME => NULL,
				],
				'test01',
			],
			[
				[
					Parameters::TASK => 'stekycz\Cronner\tests\objects\TestObject - test02',
					Parameters::PERIOD => '1 hour',
					Parameters::DAYS => ['Mon', 'Wed', 'Fri',],
					Parameters::TIME => [
						[
							'from' => '09:00',
							'to' => '10:00',
						],
						[
							'from' => '15:00',
							'to' => '16:00',
						],
					],
				],
				'test02',
			],
			[
				[
					Parameters::TASK => 'Test 3',
					Parameters::PERIOD => '17 minutes',
					Parameters::DAYS => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri',],
					Parameters::TIME => [
						[
							'from' => '09:00',
							'to' => '10:45',
						],
					],
				],
				'test03',
			],
			[
				[
					Parameters::TASK => 'Test 4',
					Parameters::PERIOD => '1 day',
					Parameters::DAYS => ['Sat', 'Sun',],
					Parameters::TIME => NULL,
				],
				'test04',
			],
		];
	}
<commit_msg>Set datetime now in parameters test (#64)<commit_after><?php

declare(strict_types=1);

/**
 * @testCase
 */

namespace stekycz\Cronner\tests\Tasks;

use stekycz\Cronner\Tasks\Parameters;
use stekycz\Cronner\tests\objects\TestObject;
use Tester\Assert;
use DateTime;

require_once(__DIR__ . "/../bootstrap.php");

class ParametersParsingTest extends \TestCase
{

	/**
	 * @var object
	 */
	private $object;

	protected function setUp()
	{
		parent::setUp();
		$this->object = new TestObject();
	}

	/**
	 * @dataProvider dataProviderParse
	 * @param array $expected
	 * @param string $methodName
	 */
	public function testParsesTaskSettings(array $expected, string $methodName)
	{
		if (!(new \Nette\Reflection\ClassType($this->object))->hasMethod($methodName)) {
			Assert::fail('Tested class does not have method "' . $methodName . '".');

			return;
		}

		Assert::same($expected, 
			Parameters::parseParameters(
				(new \Nette\Reflection\ClassType($this->object))->getMethod($methodName),
				new DateTime('NOW')
			)
		);
	}

	public function dataProviderParse() : array
	{
		return [
			[
				[
					Parameters::TASK => 'E-mail notifications',
					Parameters::PERIOD => '5 minutes',
					Parameters::DAYS => NULL,
					Parameters::DAYS_OF_MONTH => NULL,
					Parameters::TIME => NULL,
				],
				'test01',
			],
			[
				[
					Parameters::TASK => 'stekycz\Cronner\tests\objects\TestObject - test02',
					Parameters::PERIOD => '1 hour',
					Parameters::DAYS => ['Mon', 'Wed', 'Fri',],
					Parameters::DAYS_OF_MONTH => NULL,
					Parameters::TIME => [
						[
							'from' => '09:00',
							'to' => '10:00',
						],
						[
							'from' => '15:00',
							'to' => '16:00',
						],
					],
				],
				'test02',
			],
			[
				[
					Parameters::TASK => 'Test 3',
					Parameters::PERIOD => '17 minutes',
					Parameters::DAYS => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri',],
					Parameters::DAYS_OF_MONTH => NULL,
					Parameters::TIME => [
						[
							'from' => '09:00',
							'to' => '10:45',
						],
					],
				],
				'test03',
			],
			[
				[
					Parameters::TASK => 'Test 4',
					Parameters::PERIOD => '1 day',
					Parameters::DAYS => ['Sat', 'Sun',],
					Parameters::DAYS_OF_MONTH => NULL,
					Parameters::TIME => NULL,
				],
				'test04',
			],
		];
	}

{'fraction_non_alphanumeric': 0.18916415836999306, 'fraction_numerical': 0.019912016670525584, 'mean_word_length': 2.766346992153444, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1453128', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1470, 'n_words': 263}