本文整理汇总了PHP中bovigo\assert\assert函数的典型用法代码示例。如果您正苦于以下问题:PHP assert函数的具体用法?PHP assert怎么用?PHP assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: classAnnotatedWithSingletonWillOnlyBeCreatedOnce
/**
* @test
*/
public function classAnnotatedWithSingletonWillOnlyBeCreatedOnce()
{
$binder = new Binder();
$binder->bind(Number::class)->to(RandomSingleton::class);
$slot = $binder->getInjector()->getInstance(SlotMachine::class);
assert($slot->number1, isInstanceOf(RandomSingleton::class)->and(isSameAs($slot->number2)));
}
示例2: otherScopeIsUsedToCreateInstance
/**
* @test
*/
public function otherScopeIsUsedToCreateInstance()
{
$binder = new Binder();
$instance = new \stdClass();
$binder->bind(\stdClass::class)->to(\stdClass::class)->in(NewInstance::of(BindingScope::class)->mapCalls(['getInstance' => $instance]));
assert($binder->getInjector()->getInstance(\stdClass::class), isSameAs($instance));
}
示例3: createsInstanceIfNotPresent
/**
* @test
*/
public function createsInstanceIfNotPresent()
{
$instance = new \stdClass();
$this->prepareSession(['hasValue' => false]);
$this->provider->mapCalls(['get' => $instance]);
assert($this->sessionScope->getInstance(reflect(\stdClass::class), $this->provider), isSameAs($instance));
}
示例4: outputStreamGetsPrefix
/**
* @test
*/
public function outputStreamGetsPrefix()
{
$outputStream = NewInstance::of(OutputStream::class);
$this->streamFactory->mapCalls(['createOutputStream' => $outputStream]);
assert($this->prefixedStreamFactory->createOutputStream('foo', ['bar' => 'baz']), isSameAs($outputStream));
verify($this->streamFactory, 'createOutputStream')->received('prefix/foo', ['bar' => 'baz']);
}
示例5: injectWithProviderClass
/**
* @test
*/
public function injectWithProviderClass()
{
$binder = new Binder();
$binder->bind(Answer::class)->toProviderClass(new \ReflectionClass(MyProviderClass::class));
$question = $binder->getInjector()->getInstance(AnotherQuestion::class);
assert($question->getAnswer(), isInstanceOf(Answer::class));
}
示例6: writesToStandardOutputBuffer
/**
* @test
*/
public function writesToStandardOutputBuffer()
{
$out = new StandardOutputStream();
ob_start();
$out->write('foo');
assert(ob_get_contents(), equals('foo'));
ob_end_clean();
}
示例7: canIterateOverNonSeekableInputStream
/**
* @test
*/
public function canIterateOverNonSeekableInputStream()
{
$inputStream = NewInstance::of(InputStream::class)->mapCalls(['readLine' => onConsecutiveCalls('foo', 'bar', 'baz', ''), 'eof' => onConsecutiveCalls(false, false, false, true)]);
$content = [];
foreach (linesOf($inputStream) as $lineNumber => $line) {
$content[$lineNumber] = $line;
}
assert($content, equals([1 => 'foo', 2 => 'bar', 3 => 'baz']));
}
示例8: injectWithClosure
/**
* @test
*/
public function injectWithClosure()
{
$binder = new Binder();
$answer = new Answer();
$binder->bind(Answer::class)->toClosure(function () use($answer) {
return $answer;
});
$question = $binder->getInjector()->getInstance(AnotherQuestion::class);
assert($question, isInstanceOf(AnotherQuestion::class));
assert($question->getAnswer(), isSameAs($answer));
}
示例9: keyConsumerIsNotCalledWhenNoKeyInForeachRequested
/**
* @test
*/
public function keyConsumerIsNotCalledWhenNoKeyInForeachRequested()
{
$i = 0;
$peek = new Peek(new \ArrayIterator(['foo' => 303, 'bar' => 404, 'baz' => 505]), function () {
}, function () {
fail('Key consumer is not expected to be called');
});
foreach ($peek as $value) {
$i++;
}
assert($i, equals(3));
}
示例10: infiniteGeneratorDoesStopOnlyWhenBreakOutOfLoop
/**
* @test
*/
public function infiniteGeneratorDoesStopOnlyWhenBreakOutOfLoop()
{
$i = 0;
foreach (Generator::infinite(0, function ($value) {
return $value + 2;
}) as $key => $value) {
if (1000 > $key) {
$i++;
} else {
break;
}
}
assert($i, equals(1000));
}
示例11: createsLogDirectoryWithChangedModeIfNotExists
/**
* @test
* @dataProvider throwables
*/
public function createsLogDirectoryWithChangedModeIfNotExists($throwable)
{
$this->exceptionLogger->setFilemode(0777)->log($throwable);
assert($this->root->getChild(self::$logPath)->getPermissions(), equals(0777));
}
示例12: explicitBindingOverwritesProvidedByAnnotation
/**
* @test
*/
public function explicitBindingOverwritesProvidedByAnnotation()
{
$binder = new Binder();
$binder->bind(Person2::class)->to(Mikey::class);
assert($binder->getInjector()->getInstance(Person2::class), isInstanceOf(Mikey::class));
}
示例13: deleteWritesCorrectRequestWithVersion
/**
* @since 2.0.0
* @test
*/
public function deleteWritesCorrectRequestWithVersion()
{
$this->createHttpRequest()->delete(5, HttpVersion::HTTP_1_0);
assert($this->memory, equals(Http::lines('DELETE /foo/resource HTTP/1.0', 'Host: example.com', 'X-Binford: 6100', '')));
}
示例14: toMapPassesKeyAndValueWhenNoSelectorProvided
/**
* @test
*/
public function toMapPassesKeyAndValueWhenNoSelectorProvided()
{
assert(Sequence::of($this->people)->collect()->inMap(), equals($this->people));
}
示例15: propertyBindingUsedWhenParamHasTypeHintButIsAnnotated
/**
* @test
* @since 4.1.3
*/
public function propertyBindingUsedWhenParamHasTypeHintButIsAnnotated()
{
try {
$binder = new Binder();
$properties = new Properties(['config' => ['example.password' => 'somePassword']]);
$binder->bindProperties($properties, 'PROD');
$example = $binder->getInjector()->getInstance(Example::class);
assert($example->password, isInstanceOf(Secret::class));
} finally {
// ensure all references are removed to clean up environment
unset($properties);
$example->password = null;
unset($example);
unset($binder);
gc_collect_cycles();
}
}