<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <rodolfo@chevere.org>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Chevere\Tests;

use Chevere\Tests\src\TestActionNoParamsArrayIntResponse;
use Chevere\Workflow\Jobs;
use Chevere\Workflow\Workflow;
use PHPUnit\Framework\TestCase;
use function Chevere\Workflow\async;
use function Chevere\Workflow\sync;
use function Chevere\Workflow\workflow;

final class FunctionsTest extends TestCase
{
    public function testFunctionWorkflow(): void
    {
        $workflow = workflow();
        $this->assertEquals(new Workflow(new Jobs()), $workflow);
    }

    public function testFunctionSync(): void
    {
        $action = new TestActionNoParamsArrayIntResponse();
        $job = sync($action);
        $fileLine = __FILE__ . ':' . (__LINE__ - 1);
        $this->assertSame($fileLine, $job->caller()->__toString());
        $this->assertTrue($job->isSync());
    }

    public function testFunctionAsync(): void
    {
        $action = new TestActionNoParamsArrayIntResponse();
        $job = async($action);
        $fileLine = __FILE__ . ':' . (__LINE__ - 1);
        $this->assertSame($fileLine, $job->caller()->__toString());
        $this->assertFalse($job->isSync());
    }
}
