Skip to content

Commit

Permalink
Merge pull request #322 from reliforp/fix-test
Browse files Browse the repository at this point in the history
Change the base test class to fix the handling of the Mockery expectations
  • Loading branch information
sj-i committed Nov 19, 2023
2 parents cdb3e7e + ad6e5cb commit 07918b5
Show file tree
Hide file tree
Showing 78 changed files with 293 additions and 213 deletions.
20 changes: 20 additions & 0 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* This file is part of the reliforp/reli-prof package.
*
* (c) sji <sji@sj-i.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Reli;

use Mockery\Adapter\Phpunit\MockeryTestCase;

class BaseTestCase extends MockeryTestCase
{
}
4 changes: 2 additions & 2 deletions tests/Command/CommandEnumeratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
namespace Reli\Command;

use GlobIterator;
use PHPUnit\Framework\TestCase;
use Reli\BaseTestCase;

class CommandEnumeratorTest extends TestCase
class CommandEnumeratorTest extends BaseTestCase
{
public function testCanEnumerateCommands()
{
Expand Down
8 changes: 5 additions & 3 deletions tests/Inspector/Daemon/Dispatcher/DispatchTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace Reli\Inspector\Daemon\Dispatcher;

use Reli\BaseTestCase;
use Reli\Inspector\Daemon\Reader\Controller\PhpReaderControllerInterface;
use Reli\Lib\PhpInternals\ZendTypeReader;
use PHPUnit\Framework\TestCase;

class DispatchTableTest extends TestCase
class DispatchTableTest extends BaseTestCase
{
public function testUpdateTarget()
{
Expand All @@ -30,7 +30,9 @@ function (TargetProcessDescriptor $process_descriptor) use (&$attached) {
$attached[] = $process_descriptor->pid;
return true;
}
);
)
->times(3)
;
$worker2 = clone $worker1;
$worker3 = clone $worker1;
$workers = [$worker1, $worker2, $worker3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Reli\Inspector\Daemon\Dispatcher;

use PHPUnit\Framework\TestCase;
use Reli\BaseTestCase;

class TargetProcessDescriptorTest extends TestCase
class TargetProcessDescriptorTest extends BaseTestCase
{
public function testGetInvalid()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Inspector/Daemon/Dispatcher/TargetProcessListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

namespace Reli\Inspector\Daemon\Dispatcher;

use Reli\BaseTestCase;
use Reli\Lib\PhpInternals\ZendTypeReader;
use PHPUnit\Framework\TestCase;

class TargetProcessListTest extends TestCase
class TargetProcessListTest extends BaseTestCase
{
public function testPickOne(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Inspector/Daemon/Dispatcher/WorkerPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
namespace Reli\Inspector\Daemon\Dispatcher;

use Mockery;
use Reli\BaseTestCase;
use Reli\Inspector\Daemon\Reader\Context\PhpReaderContextCreatorInterface;
use Reli\Inspector\Daemon\Reader\Controller\PhpReaderControllerInterface;
use Reli\Inspector\Settings\GetTraceSettings\GetTraceSettings;
use Reli\Inspector\Settings\TraceLoopSettings\TraceLoopSettings;
use PHPUnit\Framework\TestCase;

class WorkerPoolTest extends TestCase
class WorkerPoolTest extends BaseTestCase
{
public function testCreate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
namespace Reli\Inspector\Daemon\Reader\Context;

use Mockery;
use Reli\BaseTestCase;
use Reli\Inspector\Daemon\AutoContextRecovering;
use Reli\Inspector\Daemon\Reader\Controller\PhpReaderControllerInterface;
use Reli\Inspector\Daemon\Reader\Controller\PhpReaderControllerProtocol;
use Reli\Inspector\Daemon\Reader\Worker\PhpReaderEntryPoint;
use Reli\Inspector\Daemon\Reader\Worker\PhpReaderWorkerProtocol;
use Reli\Lib\Amphp\ContextCreatorInterface;
use Reli\Lib\Amphp\ContextInterface;
use PHPUnit\Framework\TestCase;

class PhpReaderContextCreatorTest extends TestCase
class PhpReaderContextCreatorTest extends BaseTestCase
{
public function testCreate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace Reli\Inspector\Daemon\Reader\Controller;

use Mockery;
use Reli\BaseTestCase;
use Reli\Inspector\Daemon\AutoContextRecoveringInterface;
use Reli\Inspector\Daemon\Dispatcher\TargetProcessDescriptor;
use Reli\Inspector\Daemon\Reader\Protocol\Message\AttachMessage;
use Reli\Inspector\Daemon\Reader\Protocol\Message\SetSettingsMessage;
Expand All @@ -23,11 +25,10 @@
use Reli\Inspector\Settings\TraceLoopSettings\TraceLoopSettings;
use Reli\Lib\Amphp\ContextInterface;
use Reli\Lib\PhpInternals\ZendTypeReader;
use PHPUnit\Framework\TestCase;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallFrame;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallTrace;

final class PhpReaderControllerTest extends TestCase
final class PhpReaderControllerTest extends BaseTestCase
{
public function testStart(): void
{
Expand Down Expand Up @@ -72,6 +73,7 @@ public function testSendSettings(): void
->andReturns($protocol)
;
$php_reader_context = new PhpReaderController($context);
$php_reader_context->sendSettings($trace_loop_settings, $get_trace_settings);
}

public function testSendAttach(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Hamcrest\Matchers;
use Mockery;
use Reli\BaseTestCase;
use Reli\Inspector\Daemon\Dispatcher\TargetProcessDescriptor;
use Reli\Inspector\Daemon\Reader\Protocol\Message\DetachWorkerMessage;
use Reli\Inspector\Daemon\Reader\Protocol\Message\AttachMessage;
Expand All @@ -27,9 +28,8 @@
use Reli\Lib\PhpInternals\ZendTypeReader;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallFrame;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallTrace;
use PHPUnit\Framework\TestCase;

class PhpReaderEntryPointTest extends TestCase
class PhpReaderEntryPointTest extends BaseTestCase
{
public function testRun(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Reli\Inspector\Daemon\Searcher\Context;

use Mockery;
use Reli\BaseTestCase;
use Reli\Inspector\Daemon\Searcher\Controller\PhpSearcherControllerInterface;
use Reli\Inspector\Daemon\Searcher\Controller\PhpSearcherControllerProtocol;
use Reli\Inspector\Daemon\Searcher\Worker\PhpSearcherEntryPoint;
Expand All @@ -22,7 +23,7 @@
use Reli\Lib\Amphp\ContextInterface;
use PHPUnit\Framework\TestCase;

class PhpSearcherContextCreatorTest extends TestCase
class PhpSearcherContextCreatorTest extends BaseTestCase
{
public function testCreate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace Reli\Inspector\Daemon\Searcher\Controller;

use Mockery;
use Reli\BaseTestCase;
use Reli\Inspector\Daemon\AutoContextRecoveringInterface;
use Reli\Inspector\Daemon\Dispatcher\TargetProcessDescriptor;
use Reli\Inspector\Daemon\Dispatcher\TargetProcessList;
use Reli\Inspector\Daemon\Searcher\Protocol\Message\TargetPhpSettingsMessage;
Expand All @@ -23,7 +25,7 @@
use Reli\Lib\Amphp\ContextInterface;
use PHPUnit\Framework\TestCase;

class PhpSearcherControllerTest extends TestCase
class PhpSearcherControllerTest extends BaseTestCase
{
public function testStart(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Reli\Inspector\Daemon\Searcher\Worker;

use Mockery;
use Reli\BaseTestCase;
use Reli\Inspector\Daemon\Dispatcher\TargetProcessDescriptor;
use Reli\Inspector\Daemon\Searcher\Protocol\Message\TargetPhpSettingsMessage;
use Reli\Inspector\Daemon\Searcher\Protocol\Message\UpdateTargetProcessMessage;
Expand All @@ -24,9 +25,8 @@
use Reli\Lib\PhpInternals\ZendTypeReader;
use Reli\Lib\Process\ProcFileSystem\ThreadEnumerator;
use Reli\Lib\Process\Search\ProcessSearcherInterface;
use PHPUnit\Framework\TestCase;

class PhpSearcherEntryPointTest extends TestCase
class PhpSearcherEntryPointTest extends BaseTestCase
{
public function testRun()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace Reli\Inspector\Daemon\Searcher\Worker;

use Reli\BaseTestCase;
use Reli\Inspector\Daemon\Dispatcher\TargetProcessDescriptor;
use Reli\Lib\PhpInternals\ZendTypeReader;
use PHPUnit\Framework\TestCase;

class ProcessDescriptorCacheTest extends TestCase
class ProcessDescriptorCacheTest extends BaseTestCase
{
public function testGetSet(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Reli\Inspector\Daemon\Searcher\Worker;

use Hamcrest\Matchers;
use Reli\BaseTestCase;
use Reli\Inspector\Daemon\Dispatcher\TargetProcessDescriptor;
use Reli\Inspector\Settings\TargetPhpSettings\TargetPhpSettings;
use Reli\Lib\PhpInternals\ZendTypeReader;
Expand All @@ -22,7 +23,7 @@
use Reli\Lib\Process\ProcessSpecifier;
use PHPUnit\Framework\TestCase;

class ProcessDescriptorRetrieverTest extends TestCase
class ProcessDescriptorRetrieverTest extends BaseTestCase
{
public function testGetProcessDescriptorCached(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Inspector/Output/TopLike/StatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace Reli\Inspector\Output\TopLike;

use Reli\BaseTestCase;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallFrame;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallTrace;
use PHPUnit\Framework\TestCase;

class StatTest extends TestCase
class StatTest extends BaseTestCase
{
public function testAddTrace()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Inspector/Output/TopLike/TopLikeFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

namespace Reli\Inspector\Output\TopLike;

use Reli\BaseTestCase;
use Reli\Lib\DateTime\FixedClock;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallTrace;
use PHPUnit\Framework\TestCase;

use function PHPUnit\Framework\assertSame;

class TopLikeFormatterTest extends TestCase
class TopLikeFormatterTest extends BaseTestCase
{
public function testFormat()
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Inspector/Output/TopLike/TopLikeOutputterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
namespace Reli\Inspector\Output\TopLike;

use Mockery;
use PHPUnit\Framework\TestCase;
use Reli\BaseTestCase;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Formatter\WrappableOutputFormatterInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use Symfony\Component\Console\Terminal;

class TopLikeOutputterTest extends TestCase
class TopLikeOutputterTest extends BaseTestCase
{
public function testDisplay()
{
Expand Down Expand Up @@ -50,6 +48,8 @@ public function testDisplay()
->andReturns(
$formatter = new OutputFormatter()
)
->atLeast()
->once()
;
$section
->expects()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

namespace Reli\Inspector\Output\TraceFormatter\Compat;

use Reli\BaseTestCase;
use Reli\Lib\PhpInternals\Opcodes\OpcodeV80;
use Reli\Lib\PhpInternals\Types\Zend\Opline;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallFrame;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallTrace;
use PHPUnit\Framework\TestCase;

class CompatCallTraceFormatterTest extends TestCase
class CompatCallTraceFormatterTest extends BaseTestCase
{
/** @dataProvider dataProvider */
public function testFormat(string $expects, CallTrace $call_trace): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

use Mockery;
use Noodlehaus\Config;
use PHPUnit\Framework\TestCase;
use Reli\BaseTestCase;

class TemplatePathResolverTest extends TestCase
class TemplatePathResolverTest extends BaseTestCase
{
public function testResolve(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace Reli\Inspector\Output\TraceFormatter\Templated;

use Reli\BaseTestCase;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallFrame;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallTrace;
use PHPUnit\Framework\TestCase;

class TemplatedCallTraceFormatterTest extends TestCase
class TemplatedCallTraceFormatterTest extends BaseTestCase
{
public function testFormat(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
namespace Reli\Inspector\Output\TraceFormatter\Templated;

use Mockery;
use Reli\BaseTestCase;
use Reli\Inspector\Settings\OutputSettings\OutputSettings;
use PHPUnit\Framework\TestCase;

class TraceFormatterFactoryTest extends TestCase
class TraceFormatterFactoryTest extends BaseTestCase
{
public function testCreateFromSettingsCachedByName(): void
{
Expand Down
5 changes: 3 additions & 2 deletions tests/Inspector/Output/TraceOutput/TraceOutputFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

namespace Reli\Inspector\Output\TraceOutput;

use Reli\BaseTestCase;
use Reli\Inspector\Output\TraceFormatter\CallTraceFormatter;
use Reli\Inspector\Output\TraceFormatter\Templated\TraceFormatterFactory;
use Reli\Inspector\Settings\OutputSettings\OutputSettings;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallFrame;
use Reli\Lib\PhpProcessReader\CallTraceReader\CallTrace;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\StreamOutput;

class TraceOutputFactoryTest extends TestCase
class TraceOutputFactoryTest extends BaseTestCase
{
public function testFromSettingsAndConsoleOutput()
{
Expand Down Expand Up @@ -61,6 +61,7 @@ public function testFromSettingsAndConsoleOutput()
$call_trace_formatter->expects()
->format($test_trace)
->andReturns('formatted')
->twice()
;
$trace_output_factory = new TraceOutputFactory($trace_formatter_factory);
$trace_output1 = $trace_output_factory->fromSettingsAndConsoleOutput(
Expand Down
Loading

0 comments on commit 07918b5

Please sign in to comment.