repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/SessionBeansProperty.php
src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/SessionBeansProperty.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Proxy\Configuration\PropertyGenerator; use ProxyManager\Generator\Util\UniqueIdentifierGenerator; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\PropertyGenerator; /** * Private property to store the session beans (which which gets persisted after the request). */ class SessionBeansProperty extends PropertyGenerator { /** * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\SessionBeansProperty}. * * @throws InvalidArgumentException */ public function __construct() { parent::__construct(UniqueIdentifierGenerator::getIdentifier('sessionBeans')); $this->setVisibility(self::VISIBILITY_PRIVATE); $this->setDocBlock('@var ' . \bitExpert\Disco\Store\BeanStore::class); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/ParameterValuesProperty.php
src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/ParameterValuesProperty.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Proxy\Configuration\PropertyGenerator; use ProxyManager\Generator\Util\UniqueIdentifierGenerator; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\PropertyGenerator; /** * The property will store the parameters which can be injected into the bean creation methods. * A parameter represents a value from the application configuration. */ class ParameterValuesProperty extends PropertyGenerator { /** * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ParameterValuesProperty}. * * @throws InvalidArgumentException */ public function __construct() { parent::__construct(UniqueIdentifierGenerator::getIdentifier('parameterValues')); $this->setVisibility(self::VISIBILITY_PRIVATE); $this->setDefaultValue([]); $this->setDocBlock('@var array Collection of scalar values which can be injected into beans'); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/AliasesProperty.php
src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/AliasesProperty.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Proxy\Configuration\PropertyGenerator; use ProxyManager\Generator\Util\UniqueIdentifierGenerator; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\PropertyGenerator; /** * Private property to store alias lookups for the bean instances. */ class AliasesProperty extends PropertyGenerator { /** * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\AliasesProperty}. * * @throws InvalidArgumentException */ public function __construct() { parent::__construct(UniqueIdentifierGenerator::getIdentifier('aliases')); $this->setVisibility(self::VISIBILITY_PRIVATE); $this->setDocBlock('@var array contains a list of aliases and their bean references'); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/ForceLazyInitProperty.php
src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/ForceLazyInitProperty.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Proxy\Configuration\PropertyGenerator; use ProxyManager\Generator\Util\UniqueIdentifierGenerator; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\PropertyGenerator; /** * The forceLazyInit property is used as a marker to make sure that lazy dependencies are created * for session-aware beans. Dependencies of session beans need to be lazy so that they are rebuilt * for every new request (unless the dependency is marked is session-aware itself). */ class ForceLazyInitProperty extends PropertyGenerator { /** * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ForceLazyInitProperty}. * * @throws InvalidArgumentException */ public function __construct() { parent::__construct(UniqueIdentifierGenerator::getIdentifier('forceLazyInit')); $this->setVisibility(self::VISIBILITY_PRIVATE); $this->setDocBlock('@var bool flag to toggle if a bean gets wrapped by a LazyProxy or not'); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/BeanFactoryConfigurationProperty.php
src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/BeanFactoryConfigurationProperty.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Proxy\Configuration\PropertyGenerator; use bitExpert\Disco\BeanFactoryConfiguration; use ProxyManager\Generator\Util\UniqueIdentifierGenerator; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\PropertyGenerator; /** * Private property to store the {@link \bitExpert\Disco\BeanFactoryConfiguration}. */ class BeanFactoryConfigurationProperty extends PropertyGenerator { /** * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\BeanFactoryConfigurationProperty}. * * @throws InvalidArgumentException */ public function __construct() { parent::__construct(UniqueIdentifierGenerator::getIdentifier('config')); $this->setVisibility(self::VISIBILITY_PRIVATE); $this->setDocBlock('@var ' . BeanFactoryConfiguration::class); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/BeanPostProcessorsProperty.php
src/bitExpert/Disco/Proxy/Configuration/PropertyGenerator/BeanPostProcessorsProperty.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Proxy\Configuration\PropertyGenerator; use ProxyManager\Generator\Util\UniqueIdentifierGenerator; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\PropertyGenerator; /** * The property collects all registered instances of {@link \bitExpert\Disco\BeanPostProcessor}s. */ class BeanPostProcessorsProperty extends PropertyGenerator { /** * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\BeanPostProcessorsProperty}. * * @throws InvalidArgumentException */ public function __construct() { parent::__construct(UniqueIdentifierGenerator::getIdentifier('postProcessors')); $this->setDefaultValue([]); $this->setVisibility(self::VISIBILITY_PRIVATE); $this->setDocBlock('@var ' . \bitExpert\Disco\BeanPostProcessor::class . '[]'); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bootstrap.php
tests/bootstrap.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); // include and configure Composer autoloader include __DIR__ . '/../vendor/autoload.php'; // configure the Simple Logging Facade for PSR-3 loggers with a Monolog backend \bitExpert\Slf4PsrLog\LoggerFactory::registerFactoryCallback(function ($channel): \Monolog\Logger { if (!\Monolog\Registry::hasLogger($channel)) { \Monolog\Registry::addLogger(new \Monolog\Logger($channel)); } return \Monolog\Registry::getInstance($channel); });
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/BeanFactoryRegistryUnitTest.php
tests/bitExpert/Disco/BeanFactoryRegistryUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco; use bitExpert\Disco\Config\BeanConfiguration; use PHPUnit\Framework\TestCase; /** * Unit tests for {@link \bitExpert\Disco\BeanFactoryRegistry}. */ class BeanFactoryRegistryUnitTest extends TestCase { /** * @test */ public function returnsNullWhenNotInitialized(): void { $reflectedClass = new \ReflectionClass(BeanFactoryRegistry::class); $reflectedProperty = $reflectedClass->getProperty('beanFactory'); $reflectedProperty->setAccessible(true); $reflectedProperty->setValue(null); self::assertNull(BeanFactoryRegistry::getInstance()); } /** * @test */ public function returnsRegisteredInstance(): void { $beanFactory = new AnnotationBeanFactory(BeanConfiguration::class); BeanFactoryRegistry::register($beanFactory); self::assertSame($beanFactory, BeanFactoryRegistry::getInstance()); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/BeanFactoryConfigurationUnitTest.php
tests/bitExpert/Disco/BeanFactoryConfigurationUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco; use bitExpert\Disco\Store\SerializableBeanStore; use InvalidArgumentException; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; use ProxyManager\Autoloader\Autoloader; use ProxyManager\Autoloader\AutoloaderInterface; use ProxyManager\FileLocator\FileLocator; use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; use ProxyManager\Inflector\ClassNameInflector; /** * Unit tests for {@link \bitExpert\Disco\BeanFactoryConfiguration}. */ class BeanFactoryConfigurationUnitTest extends TestCase { /** * @test */ public function invalidProxyTargetDirThrowsException(): void { $this->expectException(InvalidArgumentException::class); new BeanFactoryConfiguration('/abc'); } /** * @test */ public function configuredProxyTargetDirCanBeRetrieved(): void { $config = new BeanFactoryConfiguration(sys_get_temp_dir()); $proxyManagerConfig = $config->getProxyManagerConfiguration(); self::assertSame(sys_get_temp_dir(), $proxyManagerConfig->getProxiesTargetDir()); } /** * @test */ public function configuredGeneratorStrategyInstanceCanBeRetrieved(): void { $config = new BeanFactoryConfiguration(sys_get_temp_dir()); $config->setProxyWriterGenerator(new EvaluatingGeneratorStrategy()); $proxyManagerConfig = $config->getProxyManagerConfiguration(); self::assertInstanceOf(EvaluatingGeneratorStrategy::class, $proxyManagerConfig->getGeneratorStrategy()); } /** * @test */ public function configuredProxyAutoloaderInstanceCanBeRetrieved(): void { /** @var AutoloaderInterface $autoloader */ $autoloader = $this->createMock(AutoloaderInterface::class); $config = new BeanFactoryConfiguration(sys_get_temp_dir()); $config->setProxyAutoloader($autoloader); $proxyManagerConfig = $config->getProxyManagerConfiguration(); self::assertSame($autoloader, $proxyManagerConfig->getProxyAutoloader()); } /** * @test */ public function enablingProxyAutoloaderRegistersAdditionalAutoloader(): void { $autoloader = new Autoloader(new FileLocator(sys_get_temp_dir()), new ClassNameInflector('AUTOLOADER')); /** @var array<callable> $autoloaderFunctionsBeforeBeanFactoryInit */ $autoloaderFunctionsBeforeBeanFactoryInit = spl_autoload_functions(); $beanFactoryConfig = new BeanFactoryConfiguration(sys_get_temp_dir()); $beanFactoryConfig->setProxyAutoloader($autoloader); /** @var array<callable> $autoloaderFunctionsAfterBeanFactoryInit */ $autoloaderFunctionsAfterBeanFactoryInit = spl_autoload_functions(); self::assertCount( count($autoloaderFunctionsBeforeBeanFactoryInit) + 1, $autoloaderFunctionsAfterBeanFactoryInit ); self::assertNotContains($autoloader, $autoloaderFunctionsBeforeBeanFactoryInit); self::assertContains($autoloader, $autoloaderFunctionsAfterBeanFactoryInit); } /** * @test */ public function existingProxyAutoloaderCanBeUnregistered(): void { /** @var AutoloaderInterface $autoloader1 */ $autoloader1 = $this->createMock(AutoloaderInterface::class); /** @var AutoloaderInterface $autoloader2 */ $autoloader2 = $this->createMock(AutoloaderInterface::class); $config = new BeanFactoryConfiguration(sys_get_temp_dir()); // Set first proxy autoloader $config->setProxyAutoloader($autoloader1); // Set second proxy autoloader to unregister the first one $config->setProxyAutoloader($autoloader2); $proxyManagerConfig = $config->getProxyManagerConfiguration(); self::assertSame($autoloader2, $proxyManagerConfig->getProxyAutoloader()); self::assertContains($autoloader2, spl_autoload_functions()); self::assertNotContains($autoloader1, spl_autoload_functions()); } /** * @test */ public function configuredBeanStoreInstanceCanBererieved(): void { $beanStore = new SerializableBeanStore(); $config = new BeanFactoryConfiguration(sys_get_temp_dir()); $config->setSessionBeanStore($beanStore); self::assertSame($beanStore, $config->getSessionBeanStore()); } /** * @test */ public function injectedInvalidProxyTargetDirThrowsException(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionCode(10); $config = new BeanFactoryConfiguration(sys_get_temp_dir()); $config->setProxyTargetDir('/abc'); } /** * @test */ public function injectedNotWritableProxyTargetDirThrowsException(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionCode(20); $config = new BeanFactoryConfiguration(sys_get_temp_dir()); $path = vfsStream::setup('root', 0x111); $config->setProxyTargetDir($path->url()); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php
tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco; use bitExpert\Disco\BeanException; use bitExpert\Disco\BeanNotFoundException; use bitExpert\Disco\Config\BeanConfiguration; use bitExpert\Disco\Config\BeanConfigurationSubclass; use bitExpert\Disco\Config\BeanConfigurationTrait; use bitExpert\Disco\Config\BeanConfigurationWithAliases; use bitExpert\Disco\Config\BeanConfigurationWithParameterizedPostProcessor; use bitExpert\Disco\Config\BeanConfigurationWithParameters; use bitExpert\Disco\Config\BeanConfigurationWithPostProcessor; use bitExpert\Disco\Config\BeanConfigurationWithPostProcessorAndParameterizedDependency; use bitExpert\Disco\Config\BeanConfigurationWithPrimitives; use bitExpert\Disco\Config\BeanConfigurationWithProtectedMethod; use bitExpert\Disco\Config\WrongReturnTypeConfiguration; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; use PHPUnit\Framework\TestCase; use ProxyManager\Proxy\ValueHolderInterface; use ProxyManager\Proxy\VirtualProxyInterface; use stdClass; /** * Unit tests for {@link \bitExpert\Disco\AnnotationBeanFactory}. */ class AnnotationBeanFactoryUnitTest extends TestCase { /** * @var AnnotationBeanFactory */ private $beanFactory; /** * {@inheritDoc} */ public function setUp(): void { parent::setUp(); $this->beanFactory = new AnnotationBeanFactory(BeanConfiguration::class); BeanFactoryRegistry::register($this->beanFactory); } /** * @test */ public function retrievingNonExistentBeanThrowsException(): void { $this->expectException(BeanNotFoundException::class); $this->beanFactory->get('serviceWhichDoesNotExist'); } /** * @test */ public function retrievingBeanWithEmptyStringThrowsException(): void { $this->expectException(BeanException::class); $this->beanFactory->get(''); } /** * @test */ public function checkForExistingBeanReturnsTrue(): void { self::assertTrue($this->beanFactory->has('nonSingletonNonLazyRequestBean')); } /** * @test */ public function checkForBeanWithEmptyIdWillReturnFalse(): void { self::assertFalse($this->beanFactory->has('')); } /** * @test */ public function checkForNonExistingBeanReturnsFalse(): void { self::assertFalse($this->beanFactory->has('serviceWhichDoesNotExist')); } /** * @test */ public function retrievingNonSingletonBeanReturnsDifferentInstances(): void { $bean = $this->beanFactory->get('nonSingletonNonLazyRequestBean'); $bean2 = $this->beanFactory->get('nonSingletonNonLazyRequestBean'); self::assertNotSame($bean, $bean2); } /** * @test */ public function retrievingNonSingletonLazyBeanReturnsDifferentInstances(): void { $bean = $this->beanFactory->get('nonSingletonLazyRequestBean'); $bean2 = $this->beanFactory->get('nonSingletonLazyRequestBean'); $bean->initializeProxy(); $bean2->initializeProxy(); self::assertInstanceOf(ValueHolderInterface::class, $bean); self::assertInstanceOf(ValueHolderInterface::class, $bean2); self::assertNotSame($bean->getWrappedValueHolderValue(), $bean2->getWrappedValueHolderValue()); } /** * @test */ public function retrievingSingletonLazyBeanReturnsTheSameInstances(): void { $bean = $this->beanFactory->get('singletonLazyRequestBean'); $bean2 = $this->beanFactory->get('singletonLazyRequestBean'); $bean->initializeProxy(); $bean2->initializeProxy(); self::assertInstanceOf(ValueHolderInterface::class, $bean); self::assertInstanceOf(ValueHolderInterface::class, $bean2); self::assertSame($bean->getWrappedValueHolderValue(), $bean2->getWrappedValueHolderValue()); } /** * @test */ public function retrievingSingletonNonLazySessionBeanReturnsDependencyAsProxy(): void { $bean = $this->beanFactory->get('singletonNonLazySessionBean'); self::assertInstanceOf(VirtualProxyInterface::class, $bean->service); } /** * @test * @runInSeparateProcess * @preserveGlobalState disabled */ public function retrievingSingletonDependencyMatchesDirectBeanAccess(): void { $dependency = $this->beanFactory->get('singletonNonLazyRequestBean'); $bean = $this->beanFactory->get('singletonNonLazySessionBean'); $dependency2 = $this->beanFactory->get('singletonNonLazyRequestBean'); $bean->service->initializeProxy(); self::assertSame($dependency, $bean->service->getWrappedValueHolderValue()); self::assertSame($dependency, $dependency2); } /** * @test */ public function sessionBeanFetchesDependencyFromBeanFactoryDuringWakeup(): void { $dependency = $this->beanFactory->get('singletonNonLazyRequestBean'); $beanBefore = $this->beanFactory->get('singletonNonLazySessionBean'); $beanBefore->service->initializeProxy(); $serialized = serialize($this->beanFactory); $this->beanFactory = unserialize($serialized); $beanAfter = $this->beanFactory->get('singletonNonLazySessionBean'); $beanAfter->service->initializeProxy(); self::assertSame($beanBefore, $beanAfter); self::assertSame($dependency, $beanBefore->service->getWrappedValueHolderValue()); self::assertSame($dependency, $beanAfter->service->getWrappedValueHolderValue()); } /** * @test */ public function initializedBeanHookGetsCalledOnlyWhenBeanGetsCreated(): void { $bean = $this->beanFactory->get('singletonInitializedService'); self::assertEquals(1, $bean->postInitCnt); // pulling the dependency a second time does not trigger the postInitialization() call! $bean = $this->beanFactory->get('singletonInitializedService'); self::assertEquals(1, $bean->postInitCnt); } /** * @test */ public function initializedBeanHookGetsCalledOnlyWhenLazyBeanGetsCreated(): void { $bean = $this->beanFactory->get('singletonLazyInitializedService'); self::assertEquals(1, $bean->postInitCnt); // pulling the dependency a second time does not trigger the postInitialization() call! $bean = $this->beanFactory->get('singletonLazyInitializedService'); self::assertEquals(1, $bean->postInitCnt); } /** * @test */ public function postProcessorHookRunsAfterBeanCreation(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPostProcessor::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('nonSingletonNonLazyRequestBean'); self::assertEquals('postProcessed', $bean->test); } /** * @test */ public function postProcessorHookRunsAfterLazyBeanCreation(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPostProcessor::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('nonSingletonLazyRequestBean'); self::assertEquals('postProcessed', $bean->test); } /** * @test */ public function beanFactoryPostProcessorAcceptsParameters(): void { $this->beanFactory = new AnnotationBeanFactory( BeanConfigurationWithParameterizedPostProcessor::class, ['test' => 'injectedValue'] ); BeanFactoryRegistry::register($this->beanFactory); /** @var SampleService $bean */ $bean = $this->beanFactory->get('nonSingletonNonLazyRequestBean'); self::assertEquals('injectedValue', $bean->test); } /** * @test */ public function beanFactoryPostProcessorCanBeConfiguredWithParameterizedDependency(): void { $this->beanFactory = new AnnotationBeanFactory( BeanConfigurationWithPostProcessorAndParameterizedDependency::class, ['test' => 'injectedValue'] ); BeanFactoryRegistry::register($this->beanFactory); /** @var SampleService $bean */ $bean = $this->beanFactory->get('nonSingletonNonLazyRequestBean'); self::assertInstanceOf(stdClass::class, $bean->test); self::assertEquals('injectedValue', $bean->test->property); } /** * @test */ public function parameterPassedToBeanFactoryGetsInjectedInBean(): void { $this->beanFactory = new AnnotationBeanFactory( BeanConfigurationWithParameters::class, ['test' => 'injectedValue'] ); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('sampleServiceWithParam'); self::assertEquals('injectedValue', $bean->test); } /** * @test */ public function nestedParameterKeyPassedToBeanFactoryGetsInjectedInBean(): void { $this->beanFactory = new AnnotationBeanFactory( BeanConfigurationWithParameters::class, [ 'test' => [ 'nested' => [ 'key' => 'injectedValue' ] ] ] ); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('sampleServiceWithNestedParamKey'); self::assertEquals('injectedValue', $bean->test); } /** * @test */ public function missingRequiredParameterWillThrowException(): void { $this->expectException(BeanException::class); $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithParameters::class); BeanFactoryRegistry::register($this->beanFactory); $this->beanFactory->get('sampleServiceWithParam'); } /** * @test */ public function missingOptionalParameter(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithParameters::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('sampleServiceWithoutRequiredParam'); self::assertNull($bean->test); } /** * @test */ public function defaultValueOfParameterDefinitionWillBeUsedWhenNoParameterWasGiven(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithParameters::class, []); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('sampleServiceWithParamDefaultValue'); self::assertEquals('myDefaultValue', $bean->test); } /** * @test */ public function subclassConfigurationCanBeCorrectlyEvaluated(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationSubclass::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('singletonNonLazySessionBeanInSubclass'); self::assertInstanceOf(MasterService::class, $bean); } /** * @test */ public function traitConfigurationCanBeCorrectlyEvaluated(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationTrait::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('nonSingletonNonLazyRequestBeanInTrait'); self::assertInstanceOf(SampleService::class, $bean); } /** * @test */ public function protectedSingletonDependencyAlwaysReturnsSameInstance(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithProtectedMethod::class); BeanFactoryRegistry::register($this->beanFactory); $bean1 = $this->beanFactory->get('masterServiceWithSingletonDependency'); $bean2 = $this->beanFactory->get('masterServiceWithSingletonDependency'); self::assertSame($bean1->service, $bean2->service); } /** * @test */ public function protectedNonSingletonDependencyReturnsDifferentInstance(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithProtectedMethod::class); BeanFactoryRegistry::register($this->beanFactory); $bean1 = $this->beanFactory->get('masterServiceWithNonSingletonDependency'); $bean2 = $this->beanFactory->get('masterServiceWithNonSingletonDependency'); self::assertNotSame($bean1->service, $bean2->service); } /** * @test */ public function protectedDependencyNotVisibleToTheCaller(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithProtectedMethod::class); BeanFactoryRegistry::register($this->beanFactory); self::assertFalse($this->beanFactory->has('singletonDependency')); } /** * @test */ public function throwsExceptionIfTypeOfReturnedObjectIsNotExpectedOfNonLazyBean(): void { $this->expectException(BeanException::class); $this->beanFactory = new AnnotationBeanFactory(WrongReturnTypeConfiguration::class); BeanFactoryRegistry::register($this->beanFactory); $this->beanFactory->get('nonLazyBeanReturningSomethingWrong'); } /** * @test */ public function throwsExceptionIfNonLazyBeanMethodDoesNotReturnAnything(): void { $this->expectException(BeanException::class); $this->beanFactory = new AnnotationBeanFactory(WrongReturnTypeConfiguration::class); BeanFactoryRegistry::register($this->beanFactory); $this->beanFactory->get('nonLazyBeanNotReturningAnything'); } /** * @test */ public function throwsExceptionIfTypeOfReturnedObjectIsNotExpectedOfLazyBean(): void { $this->expectException(BeanException::class); $this->beanFactory = new AnnotationBeanFactory(WrongReturnTypeConfiguration::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('lazyBeanReturningSomethingWrong'); $bean->setTest('test'); } /** * @test */ public function throwsExceptionIfLazyBeanMethodDoesNotReturnAnything(): void { $this->expectException(BeanException::class); $this->beanFactory = new AnnotationBeanFactory(WrongReturnTypeConfiguration::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('lazyBeanNotReturningAnything'); $bean->setTest('test'); } /** * @test */ public function retrievingArrayPrimitive(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPrimitives::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('arrayPrimitive'); self::assertTrue(is_array($bean)); } /** * @test */ public function retrievingCallablePrimitive(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPrimitives::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('callablePrimitive'); self::assertTrue(is_callable($bean)); } /** * @test */ public function retrievingBoolPrimitive(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPrimitives::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('boolPrimitive'); self::assertTrue(is_bool($bean)); } /** * @test */ public function retrievingFlotPrimitive(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPrimitives::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('floatPrimitive'); self::assertTrue(is_float($bean)); } /** * @test */ public function retrievingIntPrimitive(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPrimitives::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('intPrimitive'); self::assertTrue(is_int($bean)); } /** * @test */ public function retrievingStringPrimitive(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPrimitives::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('stringPrimitive'); self::assertTrue(is_string($bean)); } /** * @test */ public function retrievingBeanWithStringInjected(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPrimitives::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get('serviceWithStringInjected'); self::assertInstanceOf(SampleService::class, $bean); self::assertTrue(is_string($bean->test)); } /** * @test * @dataProvider beanAliasProvider * @param string $beanId * @param class-string<Object> $beanType */ public function retrievingBeanByAlias(string $beanId, string $beanType): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithAliases::class); BeanFactoryRegistry::register($this->beanFactory); $bean = $this->beanFactory->get($beanId); self::assertInstanceOf($beanType, $bean); } /** * @test */ public function retrievingProtectedBeanByAlias(): void { $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithAliases::class); BeanFactoryRegistry::register($this->beanFactory); self::assertFalse($this->beanFactory->has('internalServiceWithAlias')); self::assertTrue($this->beanFactory->has('aliasIsPublicForInternalService')); self::assertInstanceOf(SampleService::class, $this->beanFactory->get('aliasIsPublicForInternalService')); } /** * @return array<int, array<int, string>> */ public function beanAliasProvider(): array { return [ ['\my\Custom\Namespace', SampleService::class], ['my::Custom::Namespace', SampleService::class], ['Alias_With_Underscore', SampleService::class], ['123456', SampleService::class], [SampleService::class, SampleService::class], [SampleServiceInterface::class, SampleService::class], ]; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/ExtendedBeanConfigurationOverwritingParentAlias.php
tests/bitExpert/Disco/Config/ExtendedBeanConfigurationOverwritingParentAlias.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Alias; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; /** * @Configuration */ class ExtendedBeanConfigurationOverwritingParentAlias extends BeanConfigurationWithAliases { /** * @Bean({ * "aliases"={ * @Alias({"type"=true}) * } * }) * @return SampleServiceInterface */ public function extendedSampleServiceWithInterfaceReturnTypeAlias(): SampleServiceInterface { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithAliases.php
tests/bitExpert/Disco/Config/BeanConfigurationWithAliases.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Alias; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; /** * @Configuration */ class BeanConfigurationWithAliases { /** * @Bean({ * "singelton"=true, * "aliases"={ * @Alias({"name" = "\my\Custom\Namespace"}), * @Alias({"name" = "my::Custom::Namespace"}), * @Alias({"name" = "Alias_With_Underscore"}), * @Alias({"name" = "123456"}), * @Alias({"type" = true}) * } * }) */ public function sampleServiceWithAliases(): SampleService { return new SampleService(); } /** * @Bean({ * "aliases"={ * @Alias({"type"=true}) * } * }) * @return SampleServiceInterface */ public function sampleServiceWithInterfaceReturnTypeAlias(): SampleServiceInterface { return new SampleService(); } /** * @Bean({ * "aliases"={ * @Alias({"name"="aliasIsPublicForInternalService"}) * } * }) */ protected function internalServiceWithAlias(): SampleService { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfiguration.php
tests/bitExpert/Disco/Config/BeanConfiguration.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\InitializedService; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class BeanConfiguration { /** * @Bean({"singleton"=false, "lazy"=false, "scope"="session"}) */ public function nonSingletonNonLazySessionBean(): MasterService { return new MasterService($this->nonSingletonNonLazyRequestBean()); } /** * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) */ public function nonSingletonNonLazyRequestBean(): SampleService { return new SampleService(); } /** * @Bean({"singleton"=false, "lazy"=true, "scope"="session"}) */ public function nonSingletonLazySessionBean(): MasterService { return new MasterService($this->nonSingletonLazyRequestBean()); } /** * @Bean({"singleton"=false, "lazy"=true, "scope"="request"}) */ public function nonSingletonLazyRequestBean(): SampleService { return new SampleService(); } /** * @Bean({"singleton"=true, "lazy"=false, "scope"="session"}) */ public function singletonNonLazySessionBean(): MasterService { return new MasterService($this->singletonNonLazyRequestBean()); } /** * @Bean({"singleton"=true, "lazy"=false, "scope"="request"}) */ public function singletonNonLazyRequestBean(): SampleService { return new SampleService(); } /** * @Bean({"singleton"=true, "lazy"=true, "scope"="session"}) */ public function singletonLazySessionBean(): MasterService { return new MasterService($this->singletonLazyRequestBean()); } /** * @Bean({"singleton"=true, "lazy"=true, "scope"="request"}) */ public function singletonLazyRequestBean(): SampleService { return new SampleService(); } /** * @Bean({"singleton"=true, "lazy"=false, "scope"="request"}) */ public function singletonInitializedService(): InitializedService { return new InitializedService(); } /** * @Bean({"singleton"=true, "lazy"=true, "scope"="request"}) */ public function singletonLazyInitializedService(): InitializedService { return new InitializedService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithPrimitives.php
tests/bitExpert/Disco/Config/BeanConfigurationWithPrimitives.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Annotations\Parameters; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class BeanConfigurationWithPrimitives { /** * @Bean */ public function arrayPrimitive(): array { return []; } /** * @Bean */ public function callablePrimitive(): callable { return function () { }; } /** * @Bean */ public function boolPrimitive(): bool { return true; } /** * @Bean */ public function floatPrimitive(): float { return 1.23; } /** * @Bean */ public function intPrimitive(): int { return 5; } /** * @Bean */ public function serviceWithStringInjected(): SampleService { $service = new SampleService(); $service->setTest($this->stringPrimitive()); return $service; } /** * @Bean */ public function stringPrimitive(): string { return 'Disco'; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php
tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class NonExistentReturnTypeConfiguration { /** * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) */ public function nonSingletonNonLazyRequestBean(): \MyOtherClass { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php
tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class WrongReturnTypeConfiguration { /** * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) */ public function nonLazyBeanNotReturningAnything(): SampleService { } /** * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) */ public function nonLazyBeanReturningSomethingWrong(): SampleService { return new MasterService(new SampleService()); } /** * @Bean({"singleton"=false, "lazy"=true, "scope"="request"}) */ public function lazyBeanNotReturningAnything(): SampleService { } /** * @Bean({"singleton"=false, "lazy"=true, "scope"="request"}) */ public function lazyBeanReturningSomethingWrong(): SampleService { return new MasterService(new SampleService()); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationTrait.php
tests/bitExpert/Disco/Config/BeanConfigurationTrait.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Config\Traits\NonSingletonNonLazyRequestBean; /** * @Configuration */ class BeanConfigurationTrait extends BeanConfiguration { use NonSingletonNonLazyRequestBean; }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithParameters.php
tests/bitExpert/Disco/Config/BeanConfigurationWithParameters.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Annotations\Parameter; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class BeanConfigurationWithParameters { /** * @Bean({ * "singleton"=false, * "parameters"={ * @Parameter({"name" = "test"}) * } * }) */ public function sampleServiceWithParam($test = ''): SampleService { $service = new SampleService(); $service->setTest($test); return $service; } /** * @Bean({ * "singleton"=false, * "parameters"={ * @Parameter({"name" = "test", "default" = null}) * } * }) */ public function sampleServiceWithParamNull($test = ''): SampleService { $service = new SampleService(); $service->setTest($test); return $service; } /** * @Bean({ * "singleton"=false, * "parameters"={ * @Parameter({"name" = "test", "default" = true}) * } * }) */ public function sampleServiceWithParamBool($test = ''): SampleService { $service = new SampleService(); $service->setTest($test); return $service; } /** * @Bean({ * "singleton"=false, * "parameters"={ * @Parameter({"name" = "test", "default" = 0}) * } * }) */ public function sampleServiceWithParamEmpty($test = ''): SampleService { $service = new SampleService(); $service->setTest($test); return $service; } /** * @Bean({ * "singleton"=false, * "parameters"={ * @Parameter({"name" = "test.nested.key"}) * } * }) */ public function sampleServiceWithNestedParamKey($test = ''): SampleService { $service = new SampleService(); $service->setTest($test); return $service; } /** * @Bean({ * "singleton"=false, * "parameters"={ * @Parameter({"name" = "test", "default" = "myDefaultValue"}) * } * }) */ public function sampleServiceWithParamDefaultValue($test = ''): SampleService { $service = new SampleService(); $service->setTest($test); return $service; } /** * @Bean({ * "singleton"=false, * "parameters"={ * @Parameter({"name" = "test", "required" = false}) * } * }) */ public function sampleServiceWithoutRequiredParam($test = ''): SampleService { $service = new SampleService(); $service->setTest($test); return $service; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/InvalidConfiguration.php
tests/bitExpert/Disco/Config/InvalidConfiguration.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; /** * Configuration class missing the needed annotation. */ class InvalidConfiguration { }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationPersistence.php
tests/bitExpert/Disco/Config/BeanConfigurationPersistence.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class BeanConfigurationPersistence { /** * @Bean */ public function sampleService(): SampleService { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/InterfaceConfiguration.php
tests/bitExpert/Disco/Config/InterfaceConfiguration.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Configuration; /** * @Configuration */ interface InterfaceConfiguration { }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/MissingReturnTypeConfiguration.php
tests/bitExpert/Disco/Config/MissingReturnTypeConfiguration.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class MissingReturnTypeConfiguration { /** * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) */ public function nonSingletonNonLazyRequestBean() { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php
tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\BeanPostProcessor; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\BeanFactoryPostProcessor; use bitExpert\Disco\Helper\BeanFactoryAwareService; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceBeanPostProcessor; /** * @Configuration */ class BeanConfigurationWithPostProcessor { /** * @BeanPostProcessor */ public function sampleServiceBeanPostProcessor(): SampleServiceBeanPostProcessor { return new SampleServiceBeanPostProcessor(); } /** * @Bean */ public function nonSingletonNonLazyRequestBean(): SampleService { return new SampleService(); } /** * @Bean({"lazy"=true}) */ public function nonSingletonLazyRequestBean(): SampleService { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliasesInParentClass.php
tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliasesInParentClass.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Alias; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; /** * @Configuration */ class BeanConfigurationWithConflictingAliasesInParentClass extends BeanConfigurationWithConflictingAliases { /** * @Bean({ * "aliases"={ * @Alias({"name"="SampleService3Alias"}) * } * }) * @return SampleServiceInterface */ public function sampleService3(): SampleServiceInterface { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithProtectedMethod.php
tests/bitExpert/Disco/Config/BeanConfigurationWithProtectedMethod.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class BeanConfigurationWithProtectedMethod { /** * @Bean({"singleton"=false}) */ public function masterServiceWithSingletonDependency(): MasterService { return new MasterService($this->singletonDependency()); } /** * @Bean({"singleton"=true}) */ protected function singletonDependency(): SampleService { return new SampleService(); } /** * @Bean({"singleton"=false}) */ public function masterServiceWithNonSingletonDependency(): MasterService { return new MasterService($this->nonSingletonDependency()); } /** * @Bean({"singleton"=false}) */ protected function nonSingletonDependency(): SampleService { return new SampleService(); } protected function nonDiRelevantFunction() { // Empty on purpose } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliases.php
tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliases.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Alias; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; /** * @Configuration */ class BeanConfigurationWithConflictingAliases { /** * @Bean({ * "aliases"={ * @Alias({"type"=true}) * } * }) * @return SampleServiceInterface */ public function sampleService1(): SampleServiceInterface { return new SampleService(); } /** * @Bean({ * "aliases"={ * @Alias({"type"=true}) * } * }) * @return SampleServiceInterface */ public function sampleService2(): SampleServiceInterface { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationSubclass.php
tests/bitExpert/Disco/Config/BeanConfigurationSubclass.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\MasterService; /** * @Configuration */ class BeanConfigurationSubclass extends BeanConfiguration { /** * @Bean({"singleton"=true, "lazy"=false, "scope"="session"}) */ public function singletonNonLazySessionBeanInSubclass(): MasterService { return new MasterService($this->singletonNonLazyRequestBean()); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithParameterizedPostProcessor.php
tests/bitExpert/Disco/Config/BeanConfigurationWithParameterizedPostProcessor.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\BeanPostProcessor; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Annotations\Parameter; use bitExpert\Disco\Helper\ParameterizedSampleServiceBeanPostProcessor; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class BeanConfigurationWithParameterizedPostProcessor { /** * @BeanPostProcessor({ * "parameters"={ * @Parameter({"name" = "test"}) * } * }) */ public function sampleServiceBeanPostProcessor($test = ''): ParameterizedSampleServiceBeanPostProcessor { return new ParameterizedSampleServiceBeanPostProcessor($test); } /** * @Bean */ public function nonSingletonNonLazyRequestBean(): SampleService { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/MissingBeanAnnotationConfiguration.php
tests/bitExpert/Disco/Config/MissingBeanAnnotationConfiguration.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class MissingBeanAnnotationConfiguration { public function nonSingletonNonLazyRequestBean() { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessorAndParameterizedDependency.php
tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessorAndParameterizedDependency.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\BeanPostProcessor; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Annotations\Parameter; use bitExpert\Disco\Helper\ParameterizedSampleServiceBeanPostProcessor; use bitExpert\Disco\Helper\SampleService; /** * @Configuration */ class BeanConfigurationWithPostProcessorAndParameterizedDependency { /** * @BeanPostProcessor */ public function sampleServiceBeanPostProcessor(): ParameterizedSampleServiceBeanPostProcessor { return new ParameterizedSampleServiceBeanPostProcessor($this->dependency()); } /** * @Bean({ * "parameters"={ * @Parameter({"name" = "test"}) * } * }) */ public function dependency($test = ''): \stdClass { $object = new \stdClass(); $object->property = $test; return $object; } /** * @Bean */ public function nonSingletonNonLazyRequestBean(): SampleService { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Config/Traits/NonSingletonNonLazyRequestBean.php
tests/bitExpert/Disco/Config/Traits/NonSingletonNonLazyRequestBean.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Config\Traits; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Helper\SampleService; trait NonSingletonNonLazyRequestBean { /** * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) */ public function nonSingletonNonLazyRequestBeanInTrait(): SampleService { return new SampleService(); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Helper/InitializedService.php
tests/bitExpert/Disco/Helper/InitializedService.php
<?php /* * This file is part of the 02003-bitExpertLabs-24-Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Helper; use bitExpert\Disco\InitializedBean; class InitializedService implements InitializedBean { /** * Counts how often postInitialization() gets invoked. * * @var int */ public $postInitCnt = 0; /** * {@inheritDoc} */ public function postInitialization(): void { $this->postInitCnt++; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Helper/SampleServiceInterface.php
tests/bitExpert/Disco/Helper/SampleServiceInterface.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Helper; interface SampleServiceInterface { }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Helper/MasterService.php
tests/bitExpert/Disco/Helper/MasterService.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Helper; class MasterService { public $service; public function __construct(SampleService $service) { $this->service = $service; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Helper/ParameterizedSampleServiceBeanPostProcessor.php
tests/bitExpert/Disco/Helper/ParameterizedSampleServiceBeanPostProcessor.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Helper; use bitExpert\Disco\BeanPostProcessor; class ParameterizedSampleServiceBeanPostProcessor implements BeanPostProcessor { protected $dependency; /** * Creates a new {@link \bitExpert\Disco\Helper\ParameterizedSampleServiceBeanPostProcessor}. * * @param mixed $dependency */ public function __construct($dependency) { $this->dependency = $dependency; } /** * {@inheritDoc} */ public function postProcess(object $bean, string $beanName): void { if ($bean instanceof SampleService) { $bean->setTest($this->dependency); } } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Helper/SampleServiceBeanPostProcessor.php
tests/bitExpert/Disco/Helper/SampleServiceBeanPostProcessor.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Helper; use bitExpert\Disco\BeanPostProcessor; class SampleServiceBeanPostProcessor implements BeanPostProcessor { /** * {@inheritDoc} */ public function postProcess(object $bean, string $beanName): void { if ($bean instanceof SampleService) { $bean->setTest('postProcessed'); } } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Helper/SampleService.php
tests/bitExpert/Disco/Helper/SampleService.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Helper; class SampleService implements SampleServiceInterface { public $test; /** * Setter method for the $test property. * * @param mixed $test */ public function setTest($test) { $this->test = $test; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Annotations/BeanPostProcessorUnitTest.php
tests/bitExpert/Disco/Annotations/BeanPostProcessorUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Annotations; use bitExpert\Disco\Helper\SampleService; use PHPUnit\Framework\TestCase; use TypeError; /** * Unit tests for {@link \bitExpert\Disco\Annotations\BeanPostProcessorUnitTest}. */ class BeanPostProcessorUnitTest extends TestCase { /** * @test */ public function configuredParametersGetReturned(): void { $bean = new Bean([ 'value' => [ 'parameters' => [ new Parameter(['value' => ['name' => 'parameterName']]), new Parameter(['value' => ['name' => 'yetAnotherParameter']]) ] ] ]); self::assertEquals( array_map( function (Parameter $parameter): string { return $parameter->getName(); }, $bean->getParameters() ), ['parameterName', 'yetAnotherParameter'] ); } /** * @test */ public function throwsExceptionIfParameterTypeDoesNotMatch(): void { $this->expectException(TypeError::class); $bean = new Bean([ 'value' => [ 'parameters' => [ new SampleService() ] ] ]); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Annotations/AnnotationAttributeParserUnitTest.php
tests/bitExpert/Disco/Annotations/AnnotationAttributeParserUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Annotations; use PHPUnit\Framework\TestCase; /** * Unit tests for {@link \bitExpert\Disco\Annotations\AnnotationAttributeParser}. */ class AnnotationAttributeParserUnitTest extends TestCase { /** * @test * @dataProvider requireDataProvider * @param mixed $parameterValue * @param mixed $expectedValue */ public function requireGetsRecognizedCorrectly(mixed $parameterValue, mixed $expectedValue): void { self::assertSame($expectedValue, AnnotationAttributeParser::parseBooleanValue($parameterValue)); } /** * @return array<mixed, mixed> */ public function requireDataProvider(): array { $callable = function (): void { }; return [ [true, true], [false, false], ['true', true], ['false', false], ['anything else', false], [1, true], [0, false], [new \stdClass(), false], [[], false], [$callable, false] ]; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Annotations/BeanUnitTest.php
tests/bitExpert/Disco/Annotations/BeanUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Annotations; use bitExpert\Disco\Helper\SampleService; use PHPUnit\Framework\TestCase; use TypeError; /** * Unit tests for {@link \bitExpert\Disco\Annotations\Bean}. */ class BeanUnitTest extends TestCase { /** * @test */ public function emptyAttributesArraySetsDefaultValues(): void { $bean = new Bean(); self::assertTrue($bean->isRequest()); self::assertFalse($bean->isSession()); self::assertTrue($bean->isSingleton()); self::assertFalse($bean->isLazy()); self::assertEmpty($bean->getAliases()); self::assertEmpty($bean->getParameters()); } /** * @test */ public function markingBeanWithSessionScope(): void { $bean = new Bean(['value' => ['scope' => 'session']]); self::assertTrue($bean->isSession()); self::assertFalse($bean->isRequest()); } /** * @test */ public function markingBeanWithRequestScope(): void { $bean = new Bean(['value' => ['scope' => 'request']]); self::assertTrue($bean->isRequest()); self::assertFalse($bean->isSession()); } /** * @test */ public function markingBeanAsSingleton(): void { $bean = new Bean(['value' => ['singleton' => true]]); self::assertTrue($bean->isSingleton()); } /** * @test */ public function markingBeanAsSingletonWithString(): void { $bean = new Bean(['value' => ['singleton' => 'true']]); self::assertTrue($bean->isSingleton()); } /** * @test */ public function markingBeanAsSingletonWithInt(): void { $bean = new Bean(['value' => ['singleton' => 1]]); self::assertTrue($bean->isSingleton()); } /** * @test */ public function markingBeanAsNonSingleton(): void { $bean = new Bean(['value' => ['singleton' => false]]); self::assertFalse($bean->isSingleton()); } /** * @test */ public function markingBeanAsNonSingletonWithString(): void { $bean = new Bean(['value' => ['singleton' => 'false']]); self::assertFalse($bean->isSingleton()); } /** * @test */ public function markingBeanAsNonSingletonWithInt(): void { $bean = new Bean(['value' => ['singleton' => 0]]); self::assertFalse($bean->isSingleton()); } /** * @test */ public function markingBeanAsLazy(): void { $bean = new Bean(['value' => ['lazy' => true]]); self::assertTrue($bean->isLazy()); } /** * @test */ public function markingBeanAsLazyWithString(): void { $bean = new Bean(['value' => ['lazy' => 'true']]); self::assertTrue($bean->isLazy()); } /** * @test */ public function markingBeanAsLazyWithInt(): void { $bean = new Bean(['value' => ['lazy' => 1]]); self::assertTrue($bean->isLazy()); } /** * @test */ public function markingBeanAsNonLazy(): void { $bean = new Bean(['value' => ['lazy' => false]]); self::assertFalse($bean->isLazy()); } /** * @test */ public function markingBeanAsNonLazyWithString(): void { $bean = new Bean(['value' => ['lazy' => 'false']]); self::assertFalse($bean->isLazy()); } /** * @test */ public function markingBeanAsNonLazyWithInt(): void { $bean = new Bean(['value' => ['lazy' => 0]]); self::assertFalse($bean->isLazy()); } /** * @test */ public function configuredAliasesGetReturned(): void { $bean = new Bean([ 'value' => [ 'aliases' => [ new Alias(['value' => ['name' => 'someAlias']]), new Alias(['value' => ['name' => 'yetAnotherAlias']]) ] ] ]); self::assertEquals( array_map( function (Alias $alias): ?string { return $alias->getName(); }, $bean->getAliases() ), ['someAlias', 'yetAnotherAlias'] ); } /** * @test */ public function throwsExceptionIfAliasTypeDoesNotMatch(): void { $this->expectException(TypeError::class); $bean = new Bean([ 'value' => [ 'aliases' => [ new SampleService() ] ] ]); } /** * @test */ public function configuredParametersGetReturned(): void { $bean = new Bean([ 'value' => [ 'parameters' => [ new Parameter(['value' => ['name' => 'parameterName']]), new Parameter(['value' => ['name' => 'yetAnotherParameter']]) ] ] ]); self::assertEquals( array_map( function (Parameter $parameter): string { return $parameter->getName(); }, $bean->getParameters() ), ['parameterName', 'yetAnotherParameter'] ); } /** * @test */ public function throwsExceptionIfParameterTypeDoesNotMatch(): void { $this->expectException(TypeError::class); $bean = new Bean([ 'value' => [ 'parameters' => [ new SampleService() ] ] ]); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Annotations/AliasUnitTest.php
tests/bitExpert/Disco/Annotations/AliasUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Annotations; use Doctrine\Common\Annotations\AnnotationException; use PHPUnit\Framework\TestCase; /** * Unit tests for {@link \bitExpert\Disco\Annotations\Alias}. */ class AliasUnitTest extends TestCase { /** * @test */ public function aliasCanBeNamedAlias(): void { $namedAlias = new Alias(['value' => ['name' => 'someAliasName']]); self::assertSame('someAliasName', $namedAlias->getName()); self::assertFalse($namedAlias->isTypeAlias()); } /** * @test */ public function aliasCannotBeNamedAliasAndTypeAlias(): void { $this->expectException(AnnotationException::class); $this->expectExceptionMessage('Type alias should not have a name!'); new Alias(['value' => ['name' => 'someAliasName', 'type' => true]]); } /** * @test */ public function aliasCanBeTypeAlias(): void { $typeAlias = new Alias(['value' => ['type' => true]]); self::assertTrue($typeAlias->isTypeAlias()); self::assertNull($typeAlias->getName()); } /** * @test */ public function aliasShouldBeNamedOrTypeAlias(): void { $this->expectException(AnnotationException::class); $this->expectExceptionMessage('Alias should either be a named alias or a type alias!'); new Alias(); } /** * @test * @dataProvider invalidNameProvider * @param mixed $name */ public function aliasNameCannotBeEmpty(mixed $name): void { $this->expectException(AnnotationException::class); $this->expectExceptionMessage('Alias should either be a named alias or a type alias!'); new Alias(['value' => ['name' => $name, 'type' => false]]); } /** * @return array<mixed> */ public function invalidNameProvider(): array { return [ [''], [0], [0.0], [false], [null], [[]], ]; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Annotations/ParameterUnitTest.php
tests/bitExpert/Disco/Annotations/ParameterUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Annotations; use Doctrine\Common\Annotations\AnnotationException; use PHPUnit\Framework\TestCase; /** * Unit tests for {@link \bitExpert\Disco\Annotations\Parameter}. */ class ParameterUnitTest extends TestCase { /** * @test */ public function missingNameWillThrowAnnotationException(): void { $this->expectException(AnnotationException::class); new Parameter(); } /** * @test */ public function parameterNameIsParsed(): void { $parameter = new Parameter(['value' => ['name' => 'myParam']]); self::assertSame('myParam', $parameter->getName()); } /** * @test */ public function defaultValueDefaultsToNull(): void { $parameter = new Parameter(['value' => ['name' => 'myParam']]); self::assertNull($parameter->getDefaultValue()); } /** * @test * @dataProvider defaultValueDataProvider * @param mixed $defaultValue */ public function defaultValueIsParsed(mixed $defaultValue): void { $parameter = new Parameter(['value' => ['name' => 'myParam', 'default' => $defaultValue]]); self::assertSame($defaultValue, $parameter->getDefaultValue()); } /** * @test */ public function requireDefaultsToTrue(): void { $parameter = new Parameter(['value' => ['name' => 'myParam']]); self::assertTrue($parameter->isRequired()); } /** * @test * @dataProvider requireDataProvider * @param bool $requireValue */ public function requireIsParsed(bool $requireValue): void { $parameter = new Parameter(['value' => ['name' => 'myParam', 'required' => $requireValue]]); self::assertSame($requireValue, $parameter->isRequired()); } /** * @return array<mixed> */ public function defaultValueDataProvider(): array { return [ 'defaultValue is a string' => ['myDefaultValue'], [0], [1], [true], [false], [null] ]; } /** * @return array<int, array<int, bool>> */ public function requireDataProvider(): array { return [ [true], [false] ]; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Store/SerializableBeanStoreUnitTest.php
tests/bitExpert/Disco/Store/SerializableBeanStoreUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Store; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; use InvalidArgumentException; use PHPUnit\Framework\TestCase; /** * Unit tests for {@link \bitExpert\Disco\Store\SerializableBeanStoreUnitTest}. */ class SerializableBeanStoreUnitTest extends TestCase { /** * @var SerializableBeanStore */ private $beanStore; /** * {@inheritdoc} */ public function setUp(): void { parent::setUp(); $this->beanStore = new SerializableBeanStore(); } /** * @test * @dataProvider beanProvider * @param mixed $bean */ public function addingAndRetrievingBeansSucceeds(mixed $bean): void { $this->beanStore->add('bean', $bean); $beanFromStore = $this->beanStore->get('bean'); self::assertSame($bean, $beanFromStore); } /** * @test */ public function addingBeanWithSameBeanIdMultipleTimeWillNotTriggerError(): void { $service = new SampleService(); $bean = new MasterService($service); $this->beanStore->add('bean', $service); $this->beanStore->add('bean', $bean); $beanFromStore = $this->beanStore->get('bean'); self::assertSame($bean, $beanFromStore); } /** * @test */ public function gettingNonExistentBeanWillThrowException(): void { $this->expectException(InvalidArgumentException::class); $this->beanStore->get('some-random-bean-instance'); } /** * @test * @dataProvider beanProvider * @param mixed $bean */ public function beanStoreCanBeSerialized(mixed $bean): void { $this->beanStore->add('bean', $bean); $beanStore = serialize($this->beanStore); $this->beanStore = unserialize($beanStore); $beanFromStore = $this->beanStore->get('bean'); self::assertEquals($bean, $beanFromStore); } /** * @return array<mixed> */ public function beanProvider(): array { return [ [new SampleService()], [1], [1.23], [false], ['some string'] ]; } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Proxy/LazyBean/LazyBeanGeneratorUnitTest.php
tests/bitExpert/Disco/Proxy/LazyBean/LazyBeanGeneratorUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Proxy\LazyBean; use Iterator; use PHPUnit\Framework\TestCase; use ProxyManager\Proxy\VirtualProxyInterface; use ReflectionClass; use Laminas\Code\Generator\ClassGenerator; /** * Unit tests for {@link \bitExpert\Disco\Proxy\LazyBean\LazyBeanGenerator}. */ class LazyBeanGeneratorUnitTest extends TestCase { /** * @test */ public function generateWithInterfaceAsOriginalObject(): void { /** @var ClassGenerator&\PHPUnit\Framework\MockObject\MockObject $classGenerator */ $classGenerator = $this->createMock(ClassGenerator::class); $classGenerator->expects(self::once()) ->method('setImplementedInterfaces') ->with(array(VirtualProxyInterface::class, Iterator::class)); $reflectionClass = new ReflectionClass(Iterator::class); self::assertTrue($reflectionClass->isInterface()); $proxyGenerator = new LazyBeanGenerator(); $proxyGenerator->generate($reflectionClass, $classGenerator); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
bitExpert/disco
https://github.com/bitExpert/disco/blob/bfccc82a4757930e4ec1259fe87c3124888e327c/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php
tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php
<?php /* * This file is part of the Disco package. * * (c) bitExpert AG * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace bitExpert\Disco\Proxy\Configuration; use bitExpert\Disco\Config\BeanConfiguration; use bitExpert\Disco\Config\BeanConfigurationWithConflictingAliases; use bitExpert\Disco\Config\BeanConfigurationWithConflictingAliasesInParentClass; use bitExpert\Disco\Config\ExtendedBeanConfigurationOverwritingParentAlias; use bitExpert\Disco\Config\BeanConfigurationWithNativeTypeAlias; use bitExpert\Disco\Config\InterfaceConfiguration; use bitExpert\Disco\Config\InvalidConfiguration; use bitExpert\Disco\Config\MissingBeanAnnotationConfiguration; use bitExpert\Disco\Config\MissingReturnTypeConfiguration; use bitExpert\Disco\Config\NonExistentReturnTypeConfiguration; use PHPUnit\Framework\TestCase; use PHPUnit_Framework_MockObject_MockObject; use ProxyManager\Exception\InvalidProxiedClassException; use Laminas\Code\Generator\ClassGenerator; /** * Unit tests for {@link \bitExpert\Disco\Proxy\Configuration\ConfigurationGenerator}. */ class ConfigurationGeneratorUnitTest extends TestCase { /** * @var ConfigurationGenerator */ private $configGenerator; /** * @var ClassGenerator&\PHPUnit\Framework\MockObject\MockObject */ private $classGenerator; /** * {@inheritDoc} */ public function setUp(): void { parent::setUp(); $this->configGenerator = new ConfigurationGenerator(); /** @var ClassGenerator&\PHPUnit\Framework\MockObject\MockObject $mock */ $mock = $this->createMock(ClassGenerator::class); $this->classGenerator = $mock; } /** * @test */ public function configClassWithoutAnAnnotationThrowsException(): void { $this->expectException(InvalidProxiedClassException::class); $reflClass = new \ReflectionClass(InvalidConfiguration::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function passingInterfaceAsConfigClassThrowsException(): void { $this->expectException(InvalidProxiedClassException::class); $reflClass = new \ReflectionClass(InterfaceConfiguration::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function missingBeanAnnotationThrowsException(): void { $this->expectException(InvalidProxiedClassException::class); $reflClass = new \ReflectionClass(MissingBeanAnnotationConfiguration::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function missingReturnTypeOfBeanDeclarationThrowsException(): void { $this->expectException(InvalidProxiedClassException::class); $reflClass = new \ReflectionClass(MissingReturnTypeConfiguration::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function nonExistentClassInReturnTypeThrowsException(): void { $this->expectException(InvalidProxiedClassException::class); $reflClass = new \ReflectionClass(NonExistentReturnTypeConfiguration::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function sameAliasUsedForMultipleBeansThrowsException(): void { $this->expectException(InvalidProxiedClassException::class); $reflClass = new \ReflectionClass(BeanConfigurationWithConflictingAliases::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function unknownAnnotationThrowsException(): void { $this->expectException(InvalidProxiedClassException::class); $this->expectExceptionMessageMatches('/^\[Semantical Error\] The annotation "@foo"/'); /** * @foo */ $configObject = new class { public function foo(): string { return 'foo'; } }; $reflClass = new \ReflectionObject($configObject); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function parsingConfigurationWithoutAnyErrorsSucceeds(): void { $this->classGenerator->expects(self::atLeastOnce()) ->method('addMethodFromGenerator'); $reflClass = new \ReflectionClass(BeanConfiguration::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function subclassedConfigurationIsAllowedToOverrwriteParentAlias(): void { $this->classGenerator->expects(self::atLeastOnce()) ->method('addMethodFromGenerator'); $reflClass = new \ReflectionClass(ExtendedBeanConfigurationOverwritingParentAlias::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } /** * @test */ public function parsingConfigurationWithConflictingAliasesInParentConfigurationFails(): void { $this->expectException(InvalidProxiedClassException::class); $reflClass = new \ReflectionClass(BeanConfigurationWithConflictingAliasesInParentClass::class); $this->configGenerator->generate($reflClass, $this->classGenerator); } }
php
Apache-2.0
bfccc82a4757930e4ec1259fe87c3124888e327c
2026-01-05T04:45:28.508624Z
false
vamsiikrishna/vex
https://github.com/vamsiikrishna/vex/blob/223d4c3c4afea421508fb18126bea1230da47cff/src/Vamsi/Vex/Command/VexCommand.php
src/Vamsi/Vex/Command/VexCommand.php
<?php namespace Vamsi\Vex\Command; use GuzzleHttp\Client; use GuzzleHttp\Pool; use GuzzleHttp\Psr7\Request; use GuzzleHttp\TransferStats; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class VexCommand extends Command { protected function configure() { $this ->setName('vex') ->setDescription('make the specified requests') ->setHelp('This command sends the specified requests to the specified URL') ->addArgument('url', InputArgument::REQUIRED, 'The URL to which the requests should be sent') ->addArgument('n', InputArgument::OPTIONAL, 'Number of requests to be made', 1) ->addArgument('c', InputArgument::OPTIONAL, 'Concurrency', 1) ->addOption('method', 'm', InputOption::VALUE_OPTIONAL, 'HTTP Method', 'GET') ->addOption('headers', 'H', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Headers', null) ->addOption('body', 'd', InputOption::VALUE_OPTIONAL, 'Request body', null); } protected function execute(InputInterface $input, OutputInterface $output): int { $array = []; $url = $input->getArgument('url'); $number_of_requests = $input->getArgument('n'); $concurrency = $input->getArgument('c'); $http_method = $input->getOption('method'); $headers = $input->getOption('headers'); $body = $input->getOption('body'); $output->writeln("Sending $number_of_requests requests with $concurrency Concurrency"); $client = new Client([ 'on_stats' => function (TransferStats $stats) use (&$array) { $time = $stats->getTransferTime(); $array[] = $time; //echo $time.PHP_EOL; //$stats->getHandlerStats(); }, ]); $progress = new ProgressBar($output, $number_of_requests); $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'); $progress->start(); $requests = function ($total) use ($url, $http_method, $headers, $body) { $uri = $url; for ($i = 0; $i < $total; $i++) { yield new Request($http_method, $uri, $headers, $body); } }; $pool = new Pool($client, $requests($number_of_requests), [ 'concurrency' => $concurrency, 'fulfilled' => function ($response, $index) use ($progress) { $progress->advance(); }, 'rejected' => function ($reason, $index) { // this is delivered each failed request }, ]); $promise = $pool->promise(); $promise->wait(); $progress->finish(); $output->writeln(''); $output->writeln('Done!'); return 0; } }
php
MIT
223d4c3c4afea421508fb18126bea1230da47cff
2026-01-05T04:45:42.677502Z
false
mnsami/composer-custom-directory-installer
https://github.com/mnsami/composer-custom-directory-installer/blob/1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9/src/Composer/CustomDirectoryInstaller/LibraryInstaller.php
src/Composer/CustomDirectoryInstaller/LibraryInstaller.php
<?php namespace Composer\CustomDirectoryInstaller; use Composer\Composer; use Composer\Package\PackageInterface; use Composer\Installer\LibraryInstaller as BaseLibraryInstaller; class LibraryInstaller extends BaseLibraryInstaller { public function getInstallPath(PackageInterface $package) { $path = PackageUtils::getPackageInstallPath($package, $this->composer); if (!empty($path)) { return $path; } /* * In case, the user didn't provide a custom path * use the default one, by calling the parent::getInstallPath function */ return parent::getInstallPath($package); } }
php
MIT
1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9
2026-01-05T04:45:50.514529Z
false
mnsami/composer-custom-directory-installer
https://github.com/mnsami/composer-custom-directory-installer/blob/1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9/src/Composer/CustomDirectoryInstaller/PluginInstaller.php
src/Composer/CustomDirectoryInstaller/PluginInstaller.php
<?php namespace Composer\CustomDirectoryInstaller; use Composer\Package\PackageInterface; use Composer\Installer\PluginInstaller as BasePluginInstaller; class PluginInstaller extends BasePluginInstaller { public function getInstallPath(PackageInterface $package) { $path = PackageUtils::getPackageInstallPath($package, $this->composer); if (!empty($path)) { return $path; } /* * In case, the user didn't provide a custom path * use the default one, by calling the parent::getInstallPath function */ return parent::getInstallPath($package); } }
php
MIT
1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9
2026-01-05T04:45:50.514529Z
false
mnsami/composer-custom-directory-installer
https://github.com/mnsami/composer-custom-directory-installer/blob/1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9/src/Composer/CustomDirectoryInstaller/PackageUtils.php
src/Composer/CustomDirectoryInstaller/PackageUtils.php
<?php namespace Composer\CustomDirectoryInstaller; use Composer\Composer; use Composer\Package\PackageInterface; class PackageUtils { public static function getPackageInstallPath(PackageInterface $package, Composer $composer) { $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); } else { $vendor = ''; $name = $prettyName; } $availableVars = compact('name', 'vendor'); $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { $availableVars['name'] = $extra['installer-name']; } if ($composer->getPackage()) { $extra = $composer->getPackage()->getExtra(); if (!empty($extra['installer-paths'])) { $customPath = self::mapCustomInstallPaths($extra['installer-paths'], $prettyName); if (false !== $customPath) { return self::templatePath($customPath, $availableVars); } } } return null; } /** * Replace vars in a path * * @param string $path * @param array $vars * @return string */ protected static function templatePath($path, array $vars = array()) { if (strpos($path, '{') !== false) { extract($vars); preg_match_all('@\{\$([A-Za-z0-9_]*)\}@i', $path, $matches); if (!empty($matches[1])) { foreach ($matches[1] as $var) { $path = str_replace('{$' . $var . '}', $$var, $path); } } } return $path; } /** * Search through a passed paths array for a custom install path. * * @param array $paths * @param string $name * @return string */ protected static function mapCustomInstallPaths(array $paths, $name) { foreach ($paths as $path => $names) { if (in_array($name, $names)) { return $path; } } return false; } }
php
MIT
1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9
2026-01-05T04:45:50.514529Z
false
mnsami/composer-custom-directory-installer
https://github.com/mnsami/composer-custom-directory-installer/blob/1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9/src/Composer/CustomDirectoryInstaller/PluginPlugin.php
src/Composer/CustomDirectoryInstaller/PluginPlugin.php
<?php namespace Composer\CustomDirectoryInstaller; use Composer\Composer; use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; class PluginPlugin implements PluginInterface { private $installer; public function activate(Composer $composer, IOInterface $io) { $this->installer = new PluginInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($this->installer); } public function deactivate(Composer $composer, IOInterface $io) { $composer->getInstallationManager()->removeInstaller($this->installer); } public function uninstall(Composer $composer, IOInterface $io) { } }
php
MIT
1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9
2026-01-05T04:45:50.514529Z
false
mnsami/composer-custom-directory-installer
https://github.com/mnsami/composer-custom-directory-installer/blob/1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9/src/Composer/CustomDirectoryInstaller/PearPlugin.php
src/Composer/CustomDirectoryInstaller/PearPlugin.php
<?php namespace Composer\CustomDirectoryInstaller; use Composer\Composer; use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; class PearPlugin implements PluginInterface { public function activate(Composer $composer, IOInterface $io) { if (!class_exists('Composer\Installer\PearInstaller')) { return; } $installer = new PearInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($installer); } public function deactivate(Composer $composer, IOInterface $io) { } public function uninstall(Composer $composer, IOInterface $io) { } }
php
MIT
1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9
2026-01-05T04:45:50.514529Z
false
mnsami/composer-custom-directory-installer
https://github.com/mnsami/composer-custom-directory-installer/blob/1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9/src/Composer/CustomDirectoryInstaller/PearInstaller.php
src/Composer/CustomDirectoryInstaller/PearInstaller.php
<?php namespace Composer\CustomDirectoryInstaller; use Composer\Package\PackageInterface; use Composer\Installer\PearInstaller as BasePearInstaller; class PearInstaller extends BasePearInstaller { public function getInstallPath(PackageInterface $package) { $path = PackageUtils::getPackageInstallPath($package, $this->composer); if (!empty($path)) { return $path; } /* * In case, the user didn't provide a custom path * use the default one, by calling the parent::getInstallPath function */ return parent::getInstallPath($package); } }
php
MIT
1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9
2026-01-05T04:45:50.514529Z
false
mnsami/composer-custom-directory-installer
https://github.com/mnsami/composer-custom-directory-installer/blob/1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9/src/Composer/CustomDirectoryInstaller/LibraryPlugin.php
src/Composer/CustomDirectoryInstaller/LibraryPlugin.php
<?php namespace Composer\CustomDirectoryInstaller; use Composer\Composer; use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; class LibraryPlugin implements PluginInterface { private LibraryInstaller $installer; public function activate(Composer $composer, IOInterface $io) { $this->installer = new LibraryInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($this->installer); } public function deactivate(Composer $composer, IOInterface $io) { $composer->getInstallationManager()->removeInstaller($this->installer); } public function uninstall(Composer $composer, IOInterface $io) { } }
php
MIT
1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9
2026-01-05T04:45:50.514529Z
false
mnsami/composer-custom-directory-installer
https://github.com/mnsami/composer-custom-directory-installer/blob/1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9/tests/Unit/PackageUtilsTest.php
tests/Unit/PackageUtilsTest.php
<?php namespace App\Tests\Unit; use Composer\CustomDirectoryInstaller\PackageUtils; use PHPUnit\Framework\TestCase; use ReflectionMethod; class PackageUtilsTest extends TestCase { public function testTemplatePathReplacesVariables() { $method = new ReflectionMethod(PackageUtils::class, 'templatePath'); $method->setAccessible(true); $result = $method->invoke(null, 'lib/{$vendor}/{$name}', ['vendor' => 'foo', 'name' => 'bar']); $this->assertSame('lib/foo/bar', $result); } public function testMapCustomInstallPathsReturnsMatchingPath() { $method = new ReflectionMethod(PackageUtils::class, 'mapCustomInstallPaths'); $method->setAccessible(true); $paths = [ 'custom/one' => ['a/b'], 'custom/two' => ['c/d'] ]; $result = $method->invoke(null, $paths, 'a/b'); $this->assertSame('custom/one', $result); $noMatch = $method->invoke(null, $paths, 'e/f'); $this->assertFalse($noMatch); } }
php
MIT
1adcc93c35f44a3a06e5cf5d2f3cf638711bedf9
2026-01-05T04:45:50.514529Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/Collection.php
src/Collection.php
<?php namespace Collections; use Collections\Exceptions\InvalidArgumentException; use Collections\Exceptions\OutOfRangeException; use ArrayIterator; /** * A collection of objects with a specified class or interface */ class Collection implements CollectionInterface { use TypeValidator; /** * The collection's encapsulated array * * @var array */ protected $items; /** * The name of the object, either class or interface, that the list works with * * @var string */ private $type; /** * Instantiates the collection by specifying what type of Object will be used. * * @param $type * @param array $items * @throws InvalidArgumentException */ public function __construct($type, array $items = []) { $type = $this->determineType($type); $this->type = $type; if ($items) { $this->validateItems($items, $this->type); } $this->items = $items; } protected function setItemsFromTrustedSource(array $items) { $this->items = $items; } /** * {@inheritdoc} */ public function getType() { return $this->type; } /** * {@inheritdoc} */ public function add($item) { $this->validateItem($item, $this->type); $items = $this->items; $items[] = $item; $col = new static($this->type); $col->setItemsFromTrustedSource($items); return $col; } /** * {@inheritdoc} */ public function clear() { return new static($this->type); } /** * {@inheritdoc} */ public function contains(callable $condition) { return (bool) $this->find($condition); } /** * {@inheritdoc} */ public function find(callable $condition) { $index = $this->findIndex($condition); return $index === -1 ? false : $this->items[$index]; } /** * {@inheritdoc} */ public function findIndex(callable $condition) { $index = -1; for ($i = 0, $collectionLength = count($this->items); $i < $collectionLength; $i++) { if ($condition($this->at($i))) { $index = $i; break; } } return $index; } /** * {@inheritdoc} */ public function at($index) { $this->validateIndex($index); return $this->items[$index]; } /** * Validates a number to be used as an index * * @param integer $index The number to be validated as an index * @throws OutOfRangeException * @throws InvalidArgumentException */ private function validateIndex($index) { $exists = $this->indexExists($index); if (!$exists) { throw new OutOfRangeException('Index out of bounds of collection'); } } /** * {@inheritdoc} */ public function indexExists($index) { if (!is_int($index)) { throw new InvalidArgumentException('Index must be an integer'); } if ($index < 0) { throw new InvalidArgumentException('Index must be a non-negative integer'); } return $index < $this->count(); } /** * {@inheritdoc} */ public function count() { return count($this->items); } /** * {@inheritdoc} */ public function filter(callable $condition) { $items = []; foreach ($this->items as $item) { if ($condition($item)) { $items[] = $item; } } $col = new static($this->type); $col->setItemsFromTrustedSource($items); return $col; } /** * {@inheritdoc} */ public function findLast(callable $condition) { $index = $this->findLastIndex($condition); return $index === -1 ? false : $this->items[$index]; } /** * {@inheritdoc} */ public function findLastIndex(callable $condition) { $index = -1; for ($i = count($this->items) - 1; $i >= 0; $i--) { if ($condition($this->items[$i])) { $index = $i; break; } } return $index; } /** * {@inheritdoc} */ public function getIterator() { return new ArrayIterator($this->items); } /** * {@inheritdoc} */ public function slice($start, $end) { if ($start < 0 || !is_int($start)) { throw new InvalidArgumentException('Start must be a non-negative integer'); } if ($end < 0 || !is_int($end)) { throw new InvalidArgumentException('End must be a positive integer'); } if ($start > $end) { throw new InvalidArgumentException('End must be greater than start'); } if ($end > $this->count() + 1) { throw new InvalidArgumentException('End must be less than the count of the items in the Collection'); } $length = $end - $start + 1; $subsetItems = array_slice($this->items, $start, $length); $col = new static($this->type); $col->setItemsFromTrustedSource($subsetItems); return $col; } /** * {@inheritdoc} */ public function insert($index, $item) { $this->validateIndex($index); $this->validateItem($item, $this->type); $partA = array_slice($this->items, 0, $index); $partB = array_slice($this->items, $index, count($this->items)); $partA[] = $item; $items = array_merge($partA, $partB); $col = new static ($this->type); $col->setItemsFromTrustedSource($items); return $col; } /** * {@inheritdoc} */ public function insertRange($index, array $items) { $this->validateIndex($index); $this->validateItems($items, $this->type); //To work with negative index, get the positive relation to 0 index $index < 0 && $index = $this->count() + $index + 1; $partA = array_slice($this->items, 0, $index); $partB = array_slice($this->items, $index, count($this->items)); $items1 = array_merge($partA, $items); $items1 = array_merge($items1, $partB); $col = new static ($this->type); $col->setItemsFromTrustedSource($items1); return $col; } /** * {@inheritdoc} */ public function without(callable $condition) { $inverse = function ($item) use ($condition) { return !$condition($item); }; return $this->filter($inverse); } /** * {@inheritdoc} */ public function removeAt($index) { $this->validateIndex($index); $items = $this->items; $partA = array_slice($items, 0, $index); $partB = array_slice($items, $index + 1, count($items)); $items = array_merge($partA, $partB); $col = new static ($this->type); $col->setItemsFromTrustedSource($items); return $col; } /** * {@inheritdoc} * @throws InvalidArgumentException */ public function reverse() { $items = array_reverse($this->items); $col = new static ($this->type); $col->setItemsFromTrustedSource($items); return $col; } /** * {@inheritdoc} */ public function sort(callable $callback) { $items = $this->items; usort($items, $callback); $col = new static ($this->type); $col->setItemsFromTrustedSource($items); return $col; } /** * {@inheritdoc} */ public function toArray() { return $this->items; } /** * {@inheritdoc} */ public function reduce(callable $callable, $initial = null) { return array_reduce($this->items, $callable, $initial); } /** * {@inheritdoc} */ public function every(callable $condition) { $response = true; foreach ($this->items as $item) { $result = $condition($item); if ($result === false) { $response = false; break; } } return $response; } /** * {@inheritdoc} */ public function drop($num) { return $this->slice($num, $this->count()); } /** * {@inheritdoc} */ public function dropRight($num) { return $num !== $this->count() ? $this->slice(0, $this->count() - $num - 1) : $this->clear(); } /** * {@inheritdoc} */ public function dropWhile(callable $condition) { $count = $this->countWhileTrue($condition); return $count ? $this->drop($count) : $this; } /** * {@inheritdoc} */ public function tail() { return $this->slice(1, $this->count()); } /** * {@inheritdoc} */ public function take($num) { if ($num > $this->count()) { $num = $this->count(); } return $this->slice(0, $num - 1); } /** * {@inheritdoc} */ public function takeRight($num) { if ($num > $this->count()) { $num = $this->count(); } return $this->slice($this->count() - $num, $this->count()); } /** * @param callable $condition * @return int */ protected function countWhileTrue(callable $condition) { $count = 0; foreach ($this->items as $item) { if (!$condition($item)) { break; } $count++; } return $count; } /** * {@inheritdoc} */ public function takeWhile(callable $condition) { $count = $this->countWhileTrue($condition); return $count ? $this->take($count) : $this->clear(); } /** * {@inheritdoc} */ public function each(callable $callable) { foreach ($this->items as $item) { $callable($item); } } /** * {@inheritdoc} */ public function map(callable $callable) { $items = []; $type = null; foreach ($this->items as $item) { $result = $callable($item); if (null === $type) { $type = gettype($result); if ($type === 'object') { $type = get_class($result); } } $items[] = $result; } if (null === $type) { $type = $this->type; } $col = new static ($type); $col->setItemsFromTrustedSource($items); return $col; } /** * {@inheritdoc} */ public function reduceRight(callable $callable, $initial = null) { $reverse = array_reverse($this->items); return array_reduce($reverse, $callable, $initial); } /** * {@inheritdoc} */ public function shuffle() { $items = $this->items; shuffle($items); $col = new static ($this->type); $col->setItemsFromTrustedSource($items); return $col; } /** * {@inheritdoc} */ public function merge($items) { if ($items instanceof CollectionInterface) { $items = $items->toArray(); } if (!is_array($items)) { throw new InvalidArgumentException('Merge must be given array or Collection'); } $this->validateItems($items, $this->type); $newItems = array_merge($this->items, $items); $col = new static ($this->type); $col->setItemsFromTrustedSource($newItems); return $col; } public function first() { if (empty($this->items)) { throw new \OutOfBoundsException('Cannot get first element of empty Collection'); } return reset($this->items); } public function last() { if (empty($this->items)) { throw new \OutOfBoundsException('Cannot get last element of empty Collection'); } return end($this->items); } public function hat() { return $this->headAndTail(); } public function headAndTail() { if ($this->count() === 0) { return [ null, null ]; } if ($this->count() === 1) { return [ $this->first(), null ]; } return [ $this->first(), $this->tail() ]; } public function popPop() { if ($this->count() >= 2) { return [ $this->last(), $this->at($this->count() - 2) ]; } if ($this->count() === 1) { return [ $this->last(), null ]; } return [ null, null ]; } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/CollectionInterface.php
src/CollectionInterface.php
<?php namespace Collections; use ArrayIterator; use Collections\Exceptions\InvalidArgumentException; use Collections\Exceptions\OutOfRangeException; /** * A collection of objects with a specified class or interface */ interface CollectionInterface extends \IteratorAggregate, \Countable { /** * Returns the type of the collection. * * @return string */ public function getType(); /** * Returns a collection with $item added. * * @param $item * @return CollectionInterface * @throws InvalidArgumentException */ public function add($item); /** * Removes every item from the collection. * * @return CollectionInterface */ public function clear(); /** * Returns true if the collection contains any items that satisfy * $condition, returns false if it contains none. * * @param callable $condition * @return bool */ public function contains(callable $condition); /** * Returns the first item in the collection that satisfies * $condition, returns false if no such item exists. * * @param callable $condition * @return mixed */ public function find(callable $condition); /** * Returns the index of the first item in the collection that satisfies * $condition, returns -1 if no such item exists. * * @param callable $condition * @return int */ public function findIndex(callable $condition); /** * Returns the item in the collection at $index. * * @param $index * @return mixed * @throws OutOfRangeException */ public function at($index); /** * Returns true if $index is within the collection's range and returns false * if it is not. * * @param $index * @return bool * @throws InvalidArgumentException */ public function indexExists($index); /** * Returns the number of items in the collection. * * @return int */ public function count(); /** * Returns a collection that only contains the items which satisfy * $condition. * * @param callable $condition * @return CollectionInterface */ public function filter(callable $condition); /** * Returns the last item in the collection that satisfies $condition, * returns false if no such item exists. * * @param callable $condition * @return mixed */ public function findLast(callable $condition); /** * Returns the index of the last item in the collection that satisfies * $condition, returns -1 if no such item exists. * * @param callable $condition * @return int */ public function findLastIndex(callable $condition); /** * Returns an array iterator for the collection. * * @return ArrayIterator */ public function getIterator(); /** * Returns a collection that contains the subset of items ranging from the * index $start to $end. * * @param $start * @param $end * @return CollectionInterface * @throws InvalidArgumentException */ public function slice($start, $end); /** * Inserts $item at $index. * * @param $index * @param $item * @throws InvalidArgumentException * @throws OutOfRangeException */ public function insert($index, $item); /** * Inserts the range $items at $index. * * @param $index * @param array $items * @throws OutOfRangeException */ public function insertRange($index, array $items); /** * Removes all of the items that satisfy $condition. * * @param callable $condition * @return Collection */ public function without(callable $condition); /** * Removes the item at $index. * * @param $index * @return CollectionInterface * @throws OutOfRangeException */ public function removeAt($index); /** * Reverses the order of the items in the collection. * * @return CollectionInterface */ public function reverse(); /** * Sorts the items in the collection using the user supplied comparison * function $callback. * * @param callable $callback * @return CollectionInterface */ public function sort(callable $callback); /** * Returns an array containing the items in the collection. * * @return array */ public function toArray(); /** * Iteratively reduces the collection to a single value using the callback * function $callable. * * @param callable $callable * @param null $initial * @return mixed */ public function reduce(callable $callable, $initial = null); /** * Returns true if every item in the collection satisfies $condition, * returns false if not. * * @param callable $condition * @return bool */ public function every(callable $condition); /** * Removes all of the items in the collection starting at index $num. * * @param $num * @return Collection * @throws InvalidArgumentException */ public function drop($num); /** * Removes all of the items in the collectioin between index 0 and $num. * * @param $num * @return Collection * @throws InvalidArgumentException */ public function dropRight($num); /** * Iteratively drops items in the collection that satisfy $condition until * an item is encountered that does not satisfy $condition. * * @param callable $condition * @return Collection */ public function dropWhile(callable $condition); /** * Removes the first item in the collection. * * @return Collection * @throws InvalidArgumentException */ public function tail(); /** * Removes all of the items in the collection starting at index $num. * * @param $num * @return Collection * @throws InvalidArgumentException */ public function take($num); /** * Removes all of the items in the collection before index $num. * * @param $num * @return Collection * @throws InvalidArgumentException */ public function takeRight($num); /** * Iterates through the collection until an item is encountered that does * not satisfy $condition, then drops all of the items starting at that * index. * * @param callable $condition * @return Collection */ public function takeWhile(callable $condition); /** * Applies the callback function $callable to each item in the collection. * * @param callable $callable */ public function each(callable $callable); /** * Returns a new instance of the collection with the callback function * $callable applied to each item. * * @param callable $callable * @return CollectionInterface */ public function map(callable $callable); /** * Iteratively reduces the collection to a single value using the callback * function $callable starting at the rightmost index. * * @param callable $callable * @param null $initial * @return mixed */ public function reduceRight(callable $callable, $initial = null); /** * Randomly reorders the items in the collection. * * @return CollectionInterface */ public function shuffle(); /** * Adds every member of $items to the collection. * * @param $items * @return CollectionInterface * @throws InvalidArgumentException */ public function merge($items); /** * Get first item of the collection * * @return mixed * @throws \OutOfBoundsException */ public function first(); /** * Get last item of the collection * * @return mixed * @throws \OutOfBoundsException */ public function last(); /** * An alias for headAndTail */ public function hat(); /** * Returns the [ $head, $tail ] of a collection. If the tail is empty, this will * return null. If the collection is empty, both will be null. This is so that you * can easily use the collection for head tail recursion */ public function headAndTail(); /** * Pop pop! Returns the last item, and the next last item * * @return mixed */ public function popPop(); }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/TypeValidator.php
src/TypeValidator.php
<?php namespace Collections; use Collections\Exceptions\InvalidArgumentException; trait TypeValidator { private function determineType($type, $keyType = false) { if (!$keyType && $this->nonScalarTypeExists($type)) { return $type; } if ($scalarType = $this->determineScalar($type)) { if ($keyType && (in_array($scalarType, ['double', 'boolean']))) { throw new InvalidArgumentException('This type is not supported as a key.'); } return $scalarType; } throw new InvalidArgumentException('This type does not exist.'); } private function nonScalarTypeExists($type) { return class_exists($type) || interface_exists($type) || in_array($type, ['array', 'object', 'callable']); } private function determineScalar($type) { $synonyms = [ 'int' => 'integer', 'float' => 'double', 'bool' => 'boolean' ]; if (array_key_exists($type, $synonyms)) { $type = $synonyms[$type]; } $types = [ 'string', 'integer', 'double', 'boolean' ]; return in_array($type, $types) ? $type : null; } /** * Validates an array of items * * @param array $items an array of items to be validated * @param type */ protected function validateItems(array $items, $type) { foreach ($items as $item) { $this->validateItem($item, $type); } } protected function validateItem($item, $target) { $type = gettype($item); $shouldBeCallable = $target === 'callable'; $isObject = $type === 'object'; $looseObjectCheck = $target === 'object'; //callable must be callable if ($shouldBeCallable && !is_callable($item)) { throw new InvalidArgumentException('Item must be callable'); } //target isn't callable, object must be an instance of target if (!$looseObjectCheck && !$shouldBeCallable && $isObject && !is_a($item, $target)) { throw new InvalidArgumentException("Item is not type or subtype of $target"); } //a non callable, non object type should match the target string if (!$shouldBeCallable && !$isObject && $type !== $target) { throw new InvalidArgumentException("Item is not of type: $target"); } } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/Dictionary.php
src/Dictionary.php
<?php namespace Collections; use ArrayAccess; use ArrayIterator; use Countable; use IteratorAggregate; class Dictionary implements DictionaryInterface { use TypeValidator; protected $storage = []; protected $keyType; protected $valType; /** * @param $keyType * @param $valType * @param array $storage * @throws Exceptions\InvalidArgumentException */ public function __construct($keyType, $valType, array $storage = []) { $this->keyType = $this->determineType($keyType, true); $this->valType = $this->determineType($valType); foreach ($storage as $key => $val) { $this->validateItem($key, $this->keyType); $this->validateItem($val, $this->valType); $this->storage[$key] = $val; } } /** * {@inheritdoc} */ public function getKeyType() { return $this->keyType; } /** * {@inheritdoc} */ public function getValueType() { return $this->valType; } /** * {@inheritdoc} */ public function exists($key) { return array_key_exists($key, $this->storage); } /** * {@inheritdoc} */ public function get($key) { return array_key_exists($key, $this->storage) ? $this->storage[$key] : null; } /** * {@inheritdoc} */ public function delete($key) { $storage = $this->storage; if (array_key_exists($key, $this->storage)) { unset($storage[$key]); } return new static($this->keyType, $this->valType, $storage); } /** * {@inheritdoc} */ public function valueExists($value) { return in_array($value, $this->storage); } /** * {@inheritdoc} */ public function getIterator() { return new ArrayIterator($this->storage); } /** * {@inheritdoc} */ public function count() { return count($this->storage); } /** * {@inheritdoc} */ public function clear() { return new static($this->keyType, $this->valType); } /** * {@inheritdoc} */ public function toArray() { return $this->storage; } /** * {@inheritdoc} */ public function filter(callable $condition) { $storage = []; foreach ($this->storage as $key => $value) { if ($condition($key, $value)) { $storage[$key] = $value; } } return new static($this->keyType, $this->valType, $storage); } /** * {@inheritdoc} */ public function without(callable $condition) { $inverse = function ($k, $v) use ($condition) { return !$condition($k, $v); }; return $this->filter($inverse); } /** * {@inheritdoc} */ public function add($key, $value) { $storage = $this->storage; $storage[$key] = $value; return new static($this->keyType, $this->valType, $storage); } /** * {@inheritdoc} */ public function each(callable $callable) { foreach ($this->storage as $key => $value) { $callable($key, $value); } } /** * {@inheritdoc} */ public function getOrElse($key, $default) { return ($this->exists($key)) ? $this->get($key) : $default; } /** * {@inheritdoc} */ public function keys() { return array_keys($this->storage); } /** * {@inheritdoc} */ public function values() { return array_values($this->storage); } /** * {@inheritdoc} */ public function map(callable $callable) { $items = []; $keyType = null; $valType = null; foreach ($this->storage as $key => $val) { list($k,$v) = $callable($key, $val); if (!isset($keyType) && !isset($valType)) { $keyType = gettype($k); $valType = gettype($v); } $items[$k] = $v; } if (null === $keyType && null === $valType) { $keyType = $this->keyType; $valType = $this->valType; } return new static($keyType, $valType, $items); } /** * {@inheritdoc} */ public function merge($newItems) { if ($newItems instanceof self) { $newItems = $newItems->toArray(); } if (!is_array($newItems)) { throw new \InvalidArgumentException('Combine must be a Dictionary or an array'); } $items = array_merge($this->storage, $newItems); return new static($this->keyType, $this->valType, $items); } /** * * {@inheritdoc} * * @param callable $callable * @return bool */ public function contains(callable $callable) { foreach ($this->storage as $key => $value) { if ($callable($key, $value)) { return true; } } return false; } /** * * {@inheritdoc} */ public function reduce(callable $callable, $initial) { $carry = $initial; foreach ($this->storage as $key => $value) { $carry = $callable($carry, $key, $value); } return $carry; } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/DictionaryInterface.php
src/DictionaryInterface.php
<?php namespace Collections; interface DictionaryInterface extends \IteratorAggregate, \Countable { /** * Returns the type of the dictionary's keys. * * @return string */ public function getKeyType(); /** * Returns the type of the dictionary's values. * * @return string */ public function getValueType(); /** * Returns true if $key is in the dictionary, returns false if it is not. * * @param $key * @return bool */ public function exists($key); /** * Returns true if the callable returns true. The callable should accept a * key and value as arguments and return a boolean. * * @param callable $callable * @param bool */ public function contains(callable $callable); /** * Returns the value associated with $key. * * @param $key * @return mixed */ public function get($key); /** * Removes the key-value pair represented by $key from the dictionary. * * @param $key * @return static */ public function delete($key); /** * Returns true if $value is in the dictionary, returns false if not. * * @param $value * @return bool */ public function valueExists($value); /** * Returns the number of key-value pairs in the dictionary. * * @return int */ public function count(); /** * Removes every key-value pair from the dictionary. * * @return static */ public function clear(); /** * Returns the key-value pairs in the dictionary as an associative array. * * @return array */ public function toArray(); /** * Returns a dictionary that only contains the key-value pairs which satisfy * $condition. * * @param callable $condition * @return static */ public function filter(callable $condition); /** * Removes all key-value pairs from the Dictionary that do not satisfy * $condition. * * @param callable $condition * @return static */ public function without(callable $condition); /** * Adds the key-value pair containing $key and $value to the dictionary. * * @param $key * @param $value * @return static * @throws Exceptions\InvalidArgumentException */ public function add($key, $value); /** * Applies the callback function $callable to each key-value pair in the * dictionary. * * @param callable $callable */ public function each(callable $callable); /** * Returns the value associated with $key in the dictionary, returns * $default if it does not. * * @param $key * @param $default * @return mixed */ public function getOrElse($key, $default); /** * Returns an array of all keys in the dictionary. * * @return array */ public function keys(); /** * Returns an array of all values in the dictionary. * * @return array */ public function values(); /** * Returns a new dictionary with the callback function $callable applied to * every key-value pair in the dictionary. * * @param callable $callable * @return static */ public function map(callable $callable); /** * Adds every key-value pair in $newItems to the dictionary. * * @param $newItems * @return static */ public function merge($newItems); /** * Reduce the dictionary to a single value. The callable should contain args: carry, key, value * * @param callable $callable * @param mixed $initial * @return mixed */ public function reduce(callable $callable, $initial); }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/Exceptions/OutOfRangeException.php
src/Exceptions/OutOfRangeException.php
<?php namespace Collections\Exceptions; /** * Occurs when an index is out of range of the collection */ class OutOfRangeException extends Exception { }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/Exceptions/Exception.php
src/Exceptions/Exception.php
<?php namespace Collections\Exceptions; /** * An Exception in the Collection */ class Exception extends \Exception { }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/Exceptions/InvalidArgumentException.php
src/Exceptions/InvalidArgumentException.php
<?php namespace Collections\Exceptions; /** * Occurs when an invalid argument is used with the Collection */ class InvalidArgumentException extends Exception { }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/src/Exceptions/ImmutableKeyException.php
src/Exceptions/ImmutableKeyException.php
<?php namespace Collections\Exceptions; class ImmutableKeyException extends Exception { }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/HeadAndTailTest.php
tests/HeadAndTailTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class HeadAndTailTest extends TestCase { public function test_head_and_tail_returns_head_and_collection_for_tail() { $col = new Collection('int', [1,2,3]); list($h,$t) = $col->headAndTail(); $this->assertEquals(1, $h); $this->assertInstanceOf('Collections\Collection', $t); $this->assertEquals([2,3], $t->toArray()); } public function test_empty_collection_returns_null_for_both() { $col = new Collection('int'); list($h,$t) = $col->headAndTail(); $this->assertNull($h); $this->assertNull($t); } public function test_collection_with_one_item_returns_head_and_null_tail() { $col = new Collection('int', [1]); list($h, $t) = $col->headAndTail(); $this->assertEquals(1, $h); $this->assertNull($t); } public function test_hat_works_the_same() { $col = new Collection('int', [1,2,3]); list( $h, $t) = $col->hat(); $this->assertEquals(1, $h); $this->assertEquals([2,3], $t->toArray()); list($h, $t) = $t->hat(); $this->assertEquals(2, $h); $this->assertEquals([3], $t->toArray()); list($h, $t) = $t->hat(); $this->assertEquals(3, $h); $this->assertNull($t); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/exampleResources.php
tests/exampleResources.php
<?php interface TestClassAInterface { public function getValue(); public function setValue($v); } class TestClassA implements TestClassAInterface{ private $v; public function __construct($v){ $this->setValue($v); } public function getValue(){ return $this->v; } public function setValue($v){ $this->v = $v; } } class TestClassB{ } class TestClassExtendsA extends TestClassA{ } class Invoker { public function __invoke() {} }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/bootstrap.php
tests/bootstrap.php
<?php require_once(__DIR__.'/../vendor/autoload.php'); require_once(__DIR__.'/exampleResources.php');
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/GetOrElseTest.php
tests/Dictionary/GetOrElseTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class GetOrElseTest extends TestCase { public function test_get_or_else() { $d = (new Dictionary('string', 'int')) ->add('a', 1) ->add('b', 2) ->add('c', 3) ->add('d', 4); $result = $d->getOrElse('a', 'default'); $result2 = $d->getOrElse('e', 'default'); $this->assertEquals(1, $result); $this->assertEquals('default', $result2); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/ContainsTest.php
tests/Dictionary/ContainsTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use Collections\Exceptions\InvalidArgumentException; use PHPUnit\Framework\TestCase; use TestClassA; use TestClassAInterface; use TestClassExtendsA; class ContainsTest extends TestCase { public function test_adding_with_okay_types_adds_to_dictionary() { $d = new Dictionary('string', 'int'); $d = $d->add('a', 1); $d = $d->add('b', 2); $d = $d->add('c', 3); $d = $d->add('d', 4); $c3 = $d->contains(function($key, $value) { return $key === 'c' && $value === 3; }); $this->assertTrue($c3); $c4 = $d->contains(function($key, $value) { return $key === 'c' && $value === 4; }); $this->assertFalse($c4); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/FilterTest.php
tests/Dictionary/FilterTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class FilterTest extends TestCase { public function test_filter() { $d = (new Dictionary('string', 'int')) ->add('a', 1) ->add('b', 2) ->add('c', 3) ->add('d', 4); $subset = $d->filter(function($k,$v) { return $v % 2 == 0; }); //original is unchanged $this->assertEquals(4, $d->count()); //new has 2 $this->assertEquals(2, $subset->count()); //new contains b and d $this->assertEquals(2, $subset->get('b')); $this->assertEquals(4, $subset->get('d')); //new is missing a and c $this->assertFalse($subset->exists('a')); $this->assertFalse($subset->exists('c')); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/WithoutTest.php
tests/Dictionary/WithoutTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class WithoutTest extends TestCase { public function test_filter() { $d = (new Dictionary('string', 'int')) ->add('a', 1) ->add('b', 2) ->add('c', 3) ->add('d', 4); $subset = $d->without(function($k,$v) { return $v % 2 == 0; }); //original is unchanged $this->assertEquals(4, $d->count()); //new has 2 $this->assertEquals(2, $subset->count()); //new does not have b and d $this->assertFalse($subset->exists('b')); $this->assertFalse($subset->exists('d')); //new has a and c $this->assertTrue($subset->exists('a')); $this->assertTrue($subset->exists('c')); $this->assertEquals(1, $subset->get('a')); $this->assertEquals(3,$subset->get('c')); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/EachTest.php
tests/Dictionary/EachTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class EachTest extends TestCase { public function test_fn_applied_to_every_item() { $d = (new Dictionary('string', 'int')) ->add('a',1) ->add('b',2); $results = []; $d->each(function($k, $v) use (&$results) { $results[$k] = $v; }); $this->assertEquals([ "a" => 1, "b" => 2], $results); } public function test_for_each_works_too() { $d = (new Dictionary('string', 'int')) ->add('a',1) ->add('b',2); $results = []; foreach ($d as $k => $v) { $results[$k] = $v; } $this->assertEquals([ "a" => 1, "b" => 2], $results); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/AddTest.php
tests/Dictionary/AddTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use Collections\Exceptions\InvalidArgumentException; use PHPUnit\Framework\TestCase; use TestClassA; use TestClassAInterface; use TestClassExtendsA; class AddTest extends TestCase { public function test_adding_with_okay_types_adds_to_dictionary() { //string key and val $d = new Dictionary('string', 'string'); $d = $d->add('testkey', 'testval'); $this->assertEquals(1, $d->count()); //int key and val $d = new Dictionary('int', 'int'); $d = $d->add(1, 42); $this->assertEquals(1, $d->count()); //integer synonymous with int $d = new Dictionary('integer', 'integer'); $d = $d->add(1, 42); $this->assertEquals(1, $d->count()); //float works as val $d = new Dictionary('string', 'float'); $d = $d->add("a", 2.0); $this->assertEquals(1, $d->count()); //double synonymous with float $d = new Dictionary('string', 'double'); $d = $d->add('b', 2.0); $this->assertEquals(1, $d->count()); //bool valid value $d = new Dictionary('int', 'bool'); $d = $d->add(1, false); $this->assertEquals(1, $d->count()); //boolean synonymous with bool $d = new Dictionary('int', 'boolean'); $d = $d->add(1, false); $this->assertEquals(1, $d->count()); //callable works as value type $d = new Dictionary('string', 'callable'); $d = $d->add('test', function(){ }); $this->assertEquals(1, $d->count()); //class works as value type $d = new Dictionary('string', 'TestClassA'); $d = $d->add('test', new TestClassA(42)); $this->assertEquals(1, $d->count()); //dervied classes, too work. $d = $d->add('test2', new TestClassExtendsA(42)); $this->assertEquals(2, $d->count()); //interface works as value type $d = new Dictionary('string', 'TestClassAInterface'); $d = $d->add('test', new TestClassA(42)); $this->assertEquals(1, $d->count()); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_adding_with_invalid_key_type_throws_ex() { $d = new dictionary('string', 'int'); $d = $d->add(4, 1977); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_adding_with_invalid_value_type_throws_ex() { $d = new dictionary('string', 'string'); $d = $d->add("Episode IV", 1977); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_array_is_invalid_key_type() { $d = new Dictionary('array', 'int'); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_object_is_invalid_key_type() { $d = new Dictionary('object', 'int'); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_callable_is_invalid_key_type() { $d = new Dictionary('callable', 'int'); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_class_is_invalid_key_type() { $d = new Dictionary('TestClassA', 'int'); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_interface_is_invalid_key_type() { $d = new Dictionary('TestClassAInterface', 'int'); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_madeup_string_is_invalid_key_type() { $d = new Dictionary('test2', 'int'); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_float_is_invalid_key_type() { $d = new Dictionary('float', 'int'); } public function test_setting_key_will_overwrite_if_exists() { $d = (new Dictionary('string', 'int')) ->add('key',1) ->add('key', 2); $this->assertEquals(2, $d->get('key')); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_ex_thrown_if_callable_is_not_passed() { $d = new Dictionary('string', 'callable'); $d = $d->add('test', 123); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/DeleteTest.php
tests/Dictionary/DeleteTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class DeleteTest extends TestCase { public function test_delete_key_creates_second_dic_without_key() { $d = (new Dictionary('string', 'int'))->add('a', 1)->add('b', 2); $this->assertEquals(2, $d->count()); $d2 = $d->delete('a'); $this->assertEquals(2, $d->count()); $this->assertEquals(1, $d2->count()); $this->assertFalse($d2->valueExists(1)); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/ValuesTest.php
tests/Dictionary/ValuesTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class ValuesTest extends TestCase { public function test_values() { $d = (new Dictionary('string', 'int')) ->add('a', 1) ->add('b', 2) ->add('c', 3) ->add('d', 4); $result = $d->values(); $expected = [1,2,3,4]; $this->assertEquals($expected, $result); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/ClearTest.php
tests/Dictionary/ClearTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class ClearTest extends TestCase { public function test_clear_creates_empty_dictionary_of_same_type() { $d = new Dictionary('string','int'); $d = $d->add('a', 1); $empty = $d->clear(); //original is unchanged $this->assertEquals(1, $d->count()); $this->assertEquals(0, $empty->count()); //key and value types should be the same $this->assertEquals($d->getKeyType(), $empty->getKeyType()); $this->assertEquals($d->getValueType(), $empty->getValueType()); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/ReduceTest.php
tests/Dictionary/ReduceTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use Collections\Exceptions\InvalidArgumentException; use PHPUnit\Framework\TestCase; use TestClassA; use TestClassAInterface; use TestClassExtendsA; class ReduceTest extends TestCase { public function test_adding_with_okay_types_adds_to_dictionary() { $d = new Dictionary('string', 'int'); $d = $d->add('a', 1); $d = $d->add('b', 2); $d = $d->add('c', 3); $d = $d->add('d', 4); $flat = $d->reduce(function($carry, $key, $value) { $carry[] = $key; $carry[] = $value; return $carry; }, []); $this->assertEquals(['a',1,'b',2,'c',3,'d',4], $flat); $lt10 = function($carry, $key, $value) { if (!$carry) return false; return $value < 10; }; $valuesLessThanTen = $d->reduce($lt10, true); $this->assertTrue($valuesLessThanTen); $d = $d->add('e',99); $valuesLessThanTen = $d->reduce($lt10, true); $this->assertFalse($valuesLessThanTen); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/ExistsTest.php
tests/Dictionary/ExistsTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class ExistsTest extends TestCase { public function test_key_exists_returns_true() { $d = (new Dictionary('string','int'))->add('a',1); $this->assertTrue($d->exists('a')); } public function test_key_exists_returns_false() { $d = (new Dictionary('string','int'))->add('a',1); $this->assertFalse($d->exists('b')); } public function test_value_exists_returns_true() { $d = (new Dictionary('string','int'))->add('a',1); $this->assertTrue($d->valueExists(1)); } public function test_value_exists_returns_false() { $d = (new Dictionary('string','int'))->add('a',1); $this->assertFalse($d->valueExists(2)); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/MergeTest.php
tests/Dictionary/MergeTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use Collections\Exceptions\InvalidArgumentException; use PHPUnit\Framework\TestCase; class MergeTest extends TestCase { public function test_can_merge_dict() { $l = (new Dictionary('string','int'))->add('a',1); $r = (new Dictionary('string','int'))->add('b',2); $m = $l->merge($r); $this->assertEquals(2, $m->count()); $this->assertEquals(1, $m->get('a')); $this->assertEquals(2, $m->get('b')); } public function test_can_merge_array() { $l = (new Dictionary('string','int'))->add('a',1); $r = [ "b" => 2 ]; $m = $l->merge($r); $this->assertEquals(2, $m->count()); $this->assertEquals(1, $m->get('a')); $this->assertEquals(2, $m->get('b')); } public function test_new_keys_overwrite_old_ones() { $l = (new dictionary('string','int'))->add('a',1); $r = (new dictionary('string','int'))->add('a',2); $m = $l->merge($r); $this->assertEquals(1, $m->count()); $this->assertEquals(2, $m->get('a')); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_merge_of_bad_types_fails() { $l = (new Dictionary('string','int'))->add('a',1); $r = (new Dictionary('string','string'))->add('b','2'); $m = $l->merge($r); } /** * @expectedException \InvalidArgumentException */ public function test_merge_of_non_array() { $d = (new Dictionary('string', 'int'))->add('a',1); $result = $d->merge(3); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/ToArrayTest.php
tests/Dictionary/ToArrayTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class ToArrayTest extends TestCase { public function test_to_array_returns_assoc_array() { $d = new Dictionary('string', 'int'); $d = $d->add('a', 1); $d = $d->add('b', 2); $d = $d->add('c', 3); $arr = $d->toArray(); $this->assertEquals(['a' => 1, 'b' => 2, 'c' => 3], $arr); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/MapTest.php
tests/Dictionary/MapTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class MapTest extends TestCase { public function test_map_infers_type_for_dict() { $d = new Dictionary('string', 'int'); $d = $d->add('a', 1); //change key to 42 $m = $d->map(function($k, $v) { return [42, $v]; }); $this->assertEquals('integer', $m->getValueType()); $this->assertEquals('integer', $m->getKeyType()); $this->assertTrue($m->exists(42)); $this->assertEquals(1, $m->get(42)); } public function test_map_example() { $d = new Dictionary('int', 'string'); $d = $d->add(1, 'a'); $d = $d->add(2, 'b'); $m = $d->map(function($k, $v) { return [$k, ord($v)]; }); $this->assertEquals('integer', $m->getValueType()); $this->assertEquals('integer', $m->getKeyType()); $this->assertEquals(97, $m->get(1)); $this->assertEquals(98, $m->get(2)); } public function test_map_empty_dictionary() { $d = new Dictionary('string', 'int'); $result = $d->map(function ($a) { return $a; }); $expected = new Dictionary('string', 'int'); $this->assertEquals($expected, $result); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Dictionary/KeysTest.php
tests/Dictionary/KeysTest.php
<?php namespace Collections\Tests\Dictionary; use Collections\Dictionary; use PHPUnit\Framework\TestCase; class KeysTest extends TestCase { public function test_keys() { $d = (new Dictionary('string', 'int')) ->add('a', 1) ->add('b', 2) ->add('c', 3) ->add('d', 4); $result = $d->keys(); $expected = ['a', 'b', 'c', 'd']; $this->assertEquals($expected, $result); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/DropTest.php
tests/Collection/DropTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class DropTest extends TestCase { /** * @var Collection */ private $col; private $items; public function setup() { $this->items = [ new TestClassA(2), new TestClassA(4), new TestClassA(6), ]; $this->col = new Collection('TestClassA', $this->items); } public function test_drop_zero_returns_identical_col() { $col = $this->col->drop(0); $this->assertEquals($this->col, $col); } public function test_drop_one_returns_list_without_first_item() { $col = $this->col->drop(1); $this->assertEquals(2, $col->count()); $this->assertEquals($this->items[1], $col->at(0)); $this->assertEquals($this->items[2], $col->at(1)); } public function test_drop_all_but_last_item_gives_list_with_one_item() { $col = $this->col->drop(2); $this->assertEquals(1, $col->count()); $this->assertEquals($this->items[2], $col->at(0)); } public function test_drop_all_gives_empty_collection() { $col = $this->col->drop(3); $this->assertEquals(0,$col->count()); } //@todo what if you exceed count? Should you drop all? }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/GetObjectNameTest.php
tests/Collection/GetObjectNameTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class GetObjectNameTest extends TestCase { public function testGetObjectName() { $col = new Collection('TestClassA'); $this->assertEquals("TestClassA", $col->getType()); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/DropRightTest.php
tests/Collection/DropRightTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class DropRightTest extends TestCase { /** * @var Collection */ private $col; private $items; public function setup() { $this->items = [ new TestClassA(2), new TestClassA(4), new TestClassA(6), ]; $this->col = new Collection('TestClassA', $this->items); } public function test_dr_zero_returns_identical_col() { $col = $this->col->dropRight(0); $this->assertEquals($this->col, $col); } public function test_dr_one_drops_last_item() { $col = $this->col->dropRight(1); $this->assertEquals(2, $col->count()); $this->assertEquals($this->items[0], $col->at(0)); $this->assertEquals($this->items[1], $col->at(1)); } public function test_dr_all_but_one_leaves_first_item() { $col = $this->col->dropRight(2); $this->assertEquals(1, $col->count()); $this->assertEquals($this->items[0], $col->at(0)); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/IndexExistsTest.php
tests/Collection/IndexExistsTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class IndexExistsTest extends TestCase { public function testIndexExits() { $col = new Collection('TestClassA', [ new TestClassA(1), new TestClassA(2) ]); $this->assertTrue($col->indexExists(0)); $this->assertTrue($col->indexExists(1)); $this->assertFalse($col->indexExists(2)); } /** * @expectedException Collections\Exceptions\InvalidArgumentException * @expectedExceptionMessage Index must be a non-negative integer */ public function testIndexExitsRejectsNegatives() { $col = new Collection('TestClassA'); $col->indexExists(-1); } /** * @expectedException Collections\Exceptions\InvalidArgumentException * @expectedExceptionMessage Index must be an integer */ public function testIndexExitsRejectsNonIntegers() { $col = new Collection('TestClassA'); $col->indexExists("wat"); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/ContainsTest.php
tests/Collection/ContainsTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class ContainsTest extends TestCase { /** * @var Collection */ private $col; public function setup() { $this->col = new Collection('TestClassA', [ new TestClassA(1), new TestClassA(2) ]); } public function test_contains_finds_target_and_returns_true() { $result = $this->col->contains(function(TestClassA $item) { return $item->getValue() == 2; }); $this->assertTrue($result); } public function test_contains_finds_when_no_match_returns_false() { $result = $this->col->contains(function(TestClassA $item) { return $item->getValue() == 42; }); $this->assertFalse($result); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/PopPopTest.php
tests/Collection/PopPopTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class PopPopTest extends TestCase { public function test_pop_pop() { $col = new Collection('int', [1,2,3,4]); $this->assertEquals([4,3], $col->popPop()); $col = new Collection('int', [1,2]); $this->assertEquals([2,1], $col->popPop()); $col = new Collection('int', [1]); $this->assertEquals([1, null], $col->popPop()); $col = new Collection('int', []); $this->assertEquals([null, null], $col->popPop()); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/FindTest.php
tests/Collection/FindTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class FindTest extends TestCase { /** * @var Collection */ private $col; public function setup() { $this->col = new Collection( 'TestClassA', [ new TestClassA(1), new TestClassA(2), new TestClassA(3), new TestClassA(4), new TestClassA(5), ] ); } public function test_find_returns_first_item_that_matches() { $isEven = function (TestClassA $item) { return $item->getValue() % 2 === 0; }; $result = $this->col->find($isEven); $this->assertEquals(new TestClassA(2), $result); } public function test_find_returns_false_if_no_match() { $isOverTen = function(TestClassA $item) { return $item->getValue() > 10; }; $result = $this->col->find($isOverTen); $this->assertFalse($result); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/DropWhileTest.php
tests/Collection/DropWhileTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class DropWhileTest extends TestCase { public function test_drop_while() { $t = new TestClassA(2); $t2 = new TestClassA(4); $t3 = new TestClassA(6); $t4 = new TestClassA(7); $t5 = new TestClassA(8); $this->col = new Collection('TestClassA'); $this->col = $this->col->add($t); $this->col = $this->col->add($t2); $this->col = $this->col->add($t3); $this->col = $this->col->add($t4); $this->col = $this->col->add($t5); $col1 = $this->col->dropWhile(function ($item) { return $item->getValue() % 2 == 0; }); $this->assertEquals(2, $col1->count()); $this->assertEquals($t4, $col1->at(0)); $this->assertEquals($t5, $col1->at(1)); $col2 = $this->col->dropWhile(function ($item) { return false; }); $this->assertEquals($this->col, $col2); $col3 = $this->col->dropWhile(function ($item) { return true; }); $this->assertEquals(0, $col3->count()); } public function test_drop_while_twice_on_same_instance() { $t = new TestClassA(2); $t2 = new TestClassA(4); $t3 = new TestClassA(6); $t4 = new TestClassA(7); $t5 = new TestClassA(8); $this->col = new Collection('TestClassA'); $this->col = $this->col->add($t); $this->col = $this->col->add($t2); $this->col = $this->col->add($t3); $this->col = $this->col->add($t4); $this->col = $this->col->add($t5); $col1 = $this->col->dropWhile(function ($item) { return $item->getValue() % 2 == 0; }); $col1 = $col1->dropWhile(function($item) { return $item->getValue() % 2 != 0; }); $this->assertEquals(1, $col1->count()); $this->assertEquals($t5, $col1->at(0)); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/SortTest.php
tests/Collection/SortTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class SortTest extends TestCase { public function test_sorts_with_callback() { $col = new Collection('int', [3,1,4,2]); $comparator = function ($a, $b) { if ($a == $b) { return 0; } return ($a < $b) ? -1 : 1; }; $sorted = $col->sort($comparator); $this->assertEquals(1, $sorted->at(0)); $this->assertEquals(2, $sorted->at(1)); $this->assertEquals(3, $sorted->at(2)); $this->assertEquals(4, $sorted->at(3)); //collection is unchanged $this->assertEquals([3,1,4,2], $col->toArray()); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/TakeWhileTest.php
tests/Collection/TakeWhileTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class TakeWhileTest extends TestCase { public function test_take_while() { $t = new TestClassA(2); $t2 = new TestClassA(4); $t3 = new TestClassA(7); $t4 = new TestClassA(9); $this->c = new Collection('TestClassA'); $this->c = $this->c->add($t); $this->c = $this->c->add($t2); $this->c = $this->c->add($t3); $this->c = $this->c->add($t4); $c1 = $this->c->takeWhile(function ($item) { return $item->getValue() % 2 == 0; }); $this->assertEquals(2, $c1->count()); $this->assertEquals($t, $c1->at(0)); $this->assertEquals($t2, $c1->at(1)); $c2 = $this->c->takeWhile(function ($item) { return true; }); $this->assertEquals($this->c, $c2); $c3 = $this->c->takeWhile(function ($item) { return false; }); $this->assertEquals(0, $c3->count()); } public function test_take_while_twice_on_same_instance() { $t = new TestClassA(2); $t2 = new TestClassA(4); $t3 = new TestClassA(7); $t4 = new TestClassA(9); $this->c = new Collection('TestClassA'); $this->c = $this->c->add($t); $this->c = $this->c->add($t2); $this->c = $this->c->add($t3); $this->c = $this->c->add($t4); $c1 = $this->c->takeWhile(function ($item) { return $item->getValue() % 2 == 0; }); $c1 = $this->c->takeWhile(function ($item) { return $item->getValue() == 2; }); $this->assertEquals(1, $c1->count()); $this->assertEquals($t, $c1->at(0)); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/TakeTest.php
tests/Collection/TakeTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class TakeTest extends TestCase { /** * @var Collection */ private $col; public function setup() { $this->col = new Collection('TestClassA', [ new TestClassA(2), new TestClassA(4), new TestClassA(6), ]); } public function test_take_one_gives_col_with_first() { $result = $this->col->take(1); $this->assertEquals(1, $result->count()); $this->assertEquals(new TestClassA(2), $result->at(0)); } public function test_take_two_gives_two_from_left() { $result = $this->col->take(2); $this->assertEquals(2, $result->count()); $this->assertEquals(new TestClassA(2), $result->at(0)); $this->assertEquals(new TestClassA(4), $result->at(1)); } public function test_take_all_gives_whole_collection() { $result = $this->col->take(3); $this->assertEquals($this->col, $result); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_take_negative_throws_ex() { $result = $this->col->take(-1); } public function test_take_returns_remainder() { $result = $this->col->take(100); $this->assertEquals(3, $result->count()); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/WithoutTest.php
tests/Collection/WithoutTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class WithoutTest extends TestCase { public function test_without_returns_items_that_do_not_match_criteria() { $col = new Collection('int',[1,2,3,4,5]); $odds = $col->without(function($item) { return $item % 2 == 0; }); $this->assertEquals(new Collection('int',[1,3,5]), $odds); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/EachTest.php
tests/Collection/EachTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class EachTest extends TestCase { public function test_each() { $c = (new Collection('int')) ->add(1) ->add(2) ->add(3) ->add(4); $results = []; $c->each(function($a) use (&$results) { $results[] = $a; }); $expected = [1,2,3,4]; $this->assertEquals($expected, $results); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/AddTest.php
tests/Collection/AddTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class AddTest extends TestCase { public function test_add_item_creates_new_col_with_item() { $col = new Collection('TestClassA'); //count should be zero $this->assertEquals(0, $col->count()); $a = new TestClassA(1); //add the item $col2 = $col->add($a); //col should be unchanged $this->assertEquals(0, $col->count()); $this->assertEquals(1, $col2->count()); $this->assertEquals($a, $col2->at(0)); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_adding_wrong_class_triggers_error() { $col = new Collection('TestClassA'); $col->add(new TestClassB()); } public function test_can_add_subtypes() { $col = new Collection('TestClassA'); $col = $col->add(new TestClassExtendsA(1)); $this->assertEquals(1, $col->count()); } public function test_collection_supports_type_integer() { $col = new Collection('integer'); $col = $col->add(1); $this->assertEquals(1, $col->count()); } public function test_collection_supports_type_int() { $col = new Collection('int'); $col = $col->add(1); $this->assertEquals(1, $col->count()); } public function test_collection_supports_type_float() { $col = new Collection('float'); $col = $col->add(1.0); $this->assertEquals(1, $col->count()); } public function test_collection_supports_type_double() { $col = new Collection('double'); $col = $col->add(1.0); $this->assertEquals(1, $col->count()); } public function test_collection_supports_strings() { $col = new Collection('string'); $col = $col->add("mystring"); $this->assertEquals(1, $col->count()); } public function test_collect_supports_bool() { $col = new Collection('bool'); $col = $col->add(true); $this->assertEquals(1, $col->count()); } public function test_collect_supports_boolean() { $col = new Collection('boolean'); $col = $col->add(true); $this->assertEquals(1, $col->count()); } public function test_collection_supports_arrays() { $col = new Collection('array'); $col = $col->add([1,2,3]); $this->assertEquals(1, $col->count()); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_collection_throws_ex_for_non_existent_type() { $col = new Collection('this_type_is_invalid'); } public function test_collection_supports_interfaces() { $col = new Collection('TestClassAInterface'); $col = $col->add(new TestClassA(1)); $this->assertEquals(1, $col->count()); } public function test_collection_supports_callables() { $col = new Collection('callable'); $col = $col->add(function(){}); $col = $col->add([ $col, 'add']); $col = $col->add(new Invoker); $this->assertEquals(3, $col->count()); } /** * @expectedException Collections\Exceptions\InvalidArgumentException */ public function test_collection_throws_ex_for_different_types() { $col = new Collection('int'); $col = $col->add('string'); } public function test_can_odd_objects() { $col = new Collection('object'); $col = $col->add(new \DateTime); $this->assertEquals(1,$col->count()); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/SliceTest.php
tests/Collection/SliceTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class SliceTest extends TestCase { /** * @var Collection */ private $c; /** * @var array */ private $items; public function setup() { $this->items = [ new TestClassA(0), new TestClassA(1), new TestClassA(2), new TestClassA(3), new TestClassA(4), new TestClassA(5), new TestClassA(6), new TestClassA(7), new TestClassA(8), new TestClassA(9), ]; $this->c = new Collection('TestClassA', $this->items); } /** * @expectedException \Collections\Exceptions\InvalidArgumentException */ public function test_slice_negative_start_throws_ex() { $this->c->slice(-1, 3); } /** * @expectedException \Collections\Exceptions\InvalidArgumentException */ public function test_slice_negative_end_throws_ex() { $this->c->slice(1, -4); } /** * @expectedException \Collections\Exceptions\InvalidArgumentException */ public function test_start_gt_end_is_invalid() { $this->c->slice(3, 2); } /** * @expectedException \Collections\Exceptions\InvalidArgumentException */ public function test_start_out_of_range_is_invalid() { $this->c->slice(20, 22); } /** * @expectedException \Collections\Exceptions\InvalidArgumentException */ public function test_end_out_of_range_is_invalid() { $this->c->slice(2, 22); } public function test_subset_within_middle_of_collection_gives_correct_indices() { $subset = $this->c->slice(2, 4); $this->assertEquals(3, $subset->count()); $this->assertEquals($this->items[2], $subset->at(0)); $this->assertEquals($this->items[3], $subset->at(1)); $this->assertEquals($this->items[4], $subset->at(2)); } public function test_subset_from_start_gives_correct_indices() { $subset = $this->c->slice(0, 1); $this->assertEquals(2, $subset->count()); $this->assertEquals($this->items[0], $subset->at(0)); $this->assertEquals($this->items[1], $subset->at(1)); } public function test_subset_to_end_gives_correct_indices() { $subset = $this->c->slice(8, 9); $this->assertEquals(2, $subset->count()); $this->assertEquals($this->items[8], $subset->at(0)); $this->assertEquals($this->items[9], $subset->at(1)); } public function test_subset_from_start_with_one_item() { $subset = $this->c->slice(0, 0); $this->assertEquals(1, $subset->count()); $this->assertEquals($this->items[0], $subset->at(0)); } public function test_subset_with_only_end() { $subset = $this->c->slice(9, 9); $this->assertEquals(1, $subset->count()); $this->assertEquals($this->items[9], $subset->at(0)); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/FindIndexTest.php
tests/Collection/FindIndexTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class FindIndexTest extends TestCase { public function testFindIndex() { $this->c = new Collection("TestClassA"); $this->c = $this->c->add(new TestClassA(2)); $this->c = $this->c->add(new TestClassA(4)); $this->c = $this->c->add(new TestClassA(6)); $this->c = $this->c->add(new TestClassA(8)); $findEven = function ($item) { return $item->getValue() % 2 == 0; }; $findOdd = function ($item) { return $item->getValue() % 2 != 0; }; $this->assertEquals(0, $this->c->findIndex($findEven)); $this->assertEquals(-1, $this->c->findIndex($findOdd)); $this->assertEquals(3, $this->c->findLastIndex($findEven)); } public function test_find_last_index_when_not_found() { $col = new Collection('int',[1,2,3]); $index = $col->findLastIndex(function($x) { return $x === 4; }); $this->assertEquals(-1, $index); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/FirstAndLastTest.php
tests/Collection/FirstAndLastTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class FirstAndLastTest extends TestCase { public function test_can_get_first_item() { $col = new Collection('integer', [1, 2, 3, 4, 5]); $this->assertSame($col->first(), 1); } /** * @expectedException \RuntimeException */ public function test_can_not_get_first_if_collection_is_empty() { (new Collection('integer'))->first(); } public function test_can_get_last_item() { $col = new Collection('integer', [1, 2, 3, 4, 5]); $this->assertSame($col->last(), 5); } /** * @expectedException \RuntimeException */ public function test_can_not_get_last_if_collection_is_empty() { (new Collection('integer'))->last(); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/FindLastTest.php
tests/Collection/FindLastTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class FindLastTest extends TestCase { public function testFindLast() { $this->c = new Collection('TestClassA'); $this->c = $this->c->add(new TestClassA(2)); $this->c = $this->c->add(new TestClassA(4)); $this->c = $this->c->add(new TestClassA(6)); $item = $this->c->findLast(function ($item) { return $item->getValue() % 2 == 0; }); $this->assertEquals($item->getValue(), 6); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false
danielgsims/php-collections
https://github.com/danielgsims/php-collections/blob/199355733ba12ac17cf1958dee1a4370a320120b/tests/Collection/ReduceRightTest.php
tests/Collection/ReduceRightTest.php
<?php use Collections\Collection; use PHPUnit\Framework\TestCase; class ReduceRightTest extends TestCase { public function test_reduce_right_add() { $this->c = new Collection('int'); $this->c = $this->c->add(1); $this->c = $this->c->add(3); $this->c = $this->c->add(10); $this->c = $this->c->add(4); $c1 = $this->c->reduceRight(function ($carry, $inc) { return $carry + $inc; }); $this->assertEquals(18, $c1); } public function test_reduce_right_sub() { $this->c = new Collection('int'); $this->c = $this->c->add(1); $this->c = $this->c->add(3); $this->c = $this->c->add(5); $this->c = $this->c->add(10); $c1 = $this->c->reduceRight(function ($carry, $inc) { return $carry - $inc; }); $this->assertEquals(-19, $c1); } public function test_reduce_right_sub_non_zero_default() { $this->c = new Collection('int'); $this->c = $this->c->add(1); $this->c = $this->c->add(3); $this->c = $this->c->add(10); $this->c = $this->c->add(4); $c1 = $this->c->reduceRight(function ($carry, $inc) { return $carry - $inc; }, 20); $this->assertEquals(2, $c1); } public function test_reduce_right_string() { $this->c = new Collection('string'); $this->c = $this->c->add('a'); $this->c = $this->c->add('b'); $this->c = $this->c->add('c'); $this->c = $this->c->add('d'); $c1 = $this->c->reduceRight(function ($carry, $inc) { return $carry .= $inc; }); $this->assertEquals('dcba', $c1); } public function test_reduce_right_string_with_default() { $this->c = new Collection('string'); $this->c = $this->c->add('a'); $this->c = $this->c->add('b'); $this->c = $this->c->add('c'); $this->c = $this->c->add('d'); $c1 = $this->c->reduceRight(function ($carry, $inc) { return $carry .= $inc; }, 'z'); $this->assertEquals('zdcba', $c1); } }
php
MIT
199355733ba12ac17cf1958dee1a4370a320120b
2026-01-05T04:46:12.589480Z
false