本文整理汇总了PHP中assertSame函数的典型用法代码示例。如果您正苦于以下问题:PHP assertSame函数的具体用法?PHP assertSame怎么用?PHP assertSame使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assertSame函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mockFactory
/**
* @test
* @profile
* @ignore(ignoreUntilFixed)
*/
public function mockFactory()
{
$mockException = Mock_Factory::mock('Components\\Test_Exception', array('test/unit/case/mock', 'Mocked Exception.'));
$mockExceptionDefault = Mock_Factory::mock('Components\\Test_Exception');
$mockRunner = Mock_Factory::mock('Components\\Test_Runner');
$mockListener = Mock_Factory::mock('Components\\Test_Listener');
$mockListener->when('onInitialize')->doReturn(true);
$mockListener->when('onExecute')->doReturn(true);
$mockListener->when('onTerminate')->doNothing();
assertTrue($mockListener->onExecute($mockRunner));
assertTrue($mockListener->onInitialize($mockRunner));
$mockLL->onTerminate($mockRunner);
assertEquals('test/unit/case/mock', $mockException->getNamespace());
assertEquals('Mocked Exception.', $mockException->getMessage());
assertEquals('test/exception', $mockExceptionDefault->getNamespace());
assertEquals('Test exception.', $mockExceptionDefault->getMessage());
$mockBindingModule = Mock_Factory::mock('Components\\Binding_Module');
$mockBindingModule->when('bind')->doAnswer(function (Binding_Module $self_, $type_) {
echo "Bound {$type_}\r\n";
return $self_->bind($type_);
});
$mockBindingModule->when('configure')->doAnswer(function (Binding_Module $self_) {
$self_->bind('Components\\Test_Runner')->toInstance(Test_Runner::get());
$self_->bind(Integer::TYPE)->toInstance(22)->named('boundInteger');
});
$injector = Injector::create($mockBindingModule);
assertSame(Test_Runner::get(), $injector->resolveInstance('Components\\Test_Runner'));
assertEquals(22, $injector->resolveInstance(Integer::TYPE, 'boundInteger'));
}
示例2: testItCanUseDifferentContainerAdapters
public function testItCanUseDifferentContainerAdapters()
{
$container = new ExampleContainer();
ExampleContainerAdapter::reset();
Configurator::apply()->withContainerAdapter(ExampleContainer::class, ExampleContainerAdapter::class)->configFromArray([])->to($container);
assertSame(1, ExampleContainerAdapter::getNumberOfInstances());
}
示例3: exportedFileOfShouldContain
/**
* @param string $code
* @param PyStringNode $csv
*
* @Then /^exported file of "([^"]*)" should contain:$/
*
* @throws ExpectationException
* @throws \Exception
*/
public function exportedFileOfShouldContain($code, PyStringNode $csv)
{
$config = $this->getFixturesContext()->getJobInstance($code)->getRawConfiguration();
$path = $this->getMainContext()->getSubcontext('job')->getJobInstancePath($code);
if (!is_file($path)) {
throw $this->getMainContext()->createExpectationException(sprintf('File "%s" doesn\'t exist', $path));
}
$delimiter = isset($config['delimiter']) ? $config['delimiter'] : ';';
$enclosure = isset($config['enclosure']) ? $config['enclosure'] : '"';
$escape = isset($config['escape']) ? $config['escape'] : '\\';
$csvFile = new \SplFileObject($path);
$csvFile->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
$csvFile->setCsvControl($delimiter, $enclosure, $escape);
$expectedLines = [];
foreach ($csv->getLines() as $line) {
if (!empty($line)) {
$expectedLines[] = explode($delimiter, str_replace($enclosure, '', $line));
}
}
$actualLines = [];
while ($data = $csvFile->fgetcsv()) {
if (!empty($data)) {
$actualLines[] = array_map(function ($item) use($enclosure) {
return str_replace($enclosure, '', $item);
}, $data);
}
}
$expectedCount = count($expectedLines);
$actualCount = count($actualLines);
assertSame($expectedCount, $actualCount, sprintf('Expecting to see %d rows, found %d', $expectedCount, $actualCount));
if (md5(json_encode($actualLines[0])) !== md5(json_encode($expectedLines[0]))) {
throw new \Exception(sprintf('Header in the file %s does not match expected one: %s', $path, implode(' | ', $actualLines[0])));
}
unset($actualLines[0]);
unset($expectedLines[0]);
foreach ($expectedLines as $expectedLine) {
$originalExpectedLine = $expectedLine;
$found = false;
foreach ($actualLines as $index => $actualLine) {
// Order of columns is not ensured
// Sorting the line values allows to have two identical lines
// with values in different orders
sort($expectedLine);
sort($actualLine);
// Same thing for the rows
// Order of the rows is not reliable
// So we generate a hash for the current line and ensured that
// the generated file contains a line with the same hash
if (md5(json_encode($actualLine)) === md5(json_encode($expectedLine))) {
$found = true;
// Unset line to prevent comparing it twice
unset($actualLines[$index]);
break;
}
}
if (!$found) {
throw new \Exception(sprintf('Could not find a line containing "%s" in %s', implode(' | ', $originalExpectedLine), $path));
}
}
}
示例4: testServiceAliasDefinition
public function testServiceAliasDefinition()
{
$definition = new ServiceDefinition('service_name', ['service' => __CLASS__]);
assertTrue($definition->isAlias());
assertFalse($definition->isFactory());
assertSame(__CLASS__, $definition->getClass());
}
示例5: testReturnsTheSameReaderForTheSameFileType
public function testReturnsTheSameReaderForTheSameFileType()
{
$this->createTestFile('test1.php');
$this->createTestFile('test2.php');
$reader1 = $this->factory->create($this->getTestPath('test1.php'));
$reader2 = $this->factory->create($this->getTestPath('test2.php'));
assertSame($reader1, $reader2);
}
示例6: testItAddToConfigUsingFiles
public function testItAddToConfigUsingFiles()
{
$config = ['keyB' => 'valueB'];
$this->createJSONConfigFile('config.json', $config);
Configurator::apply()->configFromArray(['keyA' => 'valueA', 'keyB' => 'valueX'])->configFromFiles($this->getTestPath('*'))->to($this->container);
assertSame('valueA', $this->container->get('config.keyA'));
assertSame('valueB', $this->container->get('config.keyB'));
}
示例7: gets_value_from_user_input
/**
* @test
* @covers Mobileka\ScopeApplicator\Laravel\InputManager::get
*/
public function gets_value_from_user_input()
{
$lim = new Mobileka\ScopeApplicator\Laravel\InputManager();
assertNull($lim->get('param'));
assertSame('no such param', $lim->get('param', 'no such param'));
// add something to request parameters
$lim->inputManager->query->set('param', 'hello');
assertEquals('hello', $lim->get('param'));
}
示例8: testGet
public function testGet()
{
$alias = new Alias('test');
$locator = $this->getMockBuilder(LocatorInterface::class)->getMock();
$locator->method('get')->will($this->returnValue(123));
/** @var LocatorInterface $locator */
assertSame(123, $alias->get($locator));
assertSame(123, $alias->get($locator));
}
示例9: gets_value_from_user_input
/**
* @test
* @covers Mobileka\ScopeApplicator\Yii2\InputManager::get
*/
public function gets_value_from_user_input()
{
$im = new Mobileka\ScopeApplicator\Yii2\InputManager();
assertNull($im->get('param'));
assertSame('no such param', $im->get('param', 'no such param'));
// add something to request parameters
$im->setQueryParams(['param' => 'hello']);
assertEquals('hello', $im->get('param'));
}
示例10: testCreateException
public function testCreateException()
{
$this->setExpectedException(\RuntimeException::class);
$this->createModels(Order::class, []);
$source = DataSource::make(Order::all());
assertSame(null, $source[0]);
$source['0.code'] = 'a1';
return;
}
示例11: testBasicFlow
public function testBasicFlow()
{
$source = [];
$e = new Endpoint($source);
assertSame($source, $e->toArray());
$source = ['name' => 'Frank', 'surname' => 'Sinatra'];
$e = new Endpoint($source);
$e->string('name');
$e->string('surname');
$e->fromSource();
$e->fromInput();
$e->validate();
$e->writeSource();
assertSame($source, $e->toArray());
}
示例12: iShouldBeAbleToNormalizeAndDenormalizeProducts
/**
* @param string $identifiers
*
* @Then /^I should be able to normalize and denormalize (?:the )?products? (.*)$/
*/
public function iShouldBeAbleToNormalizeAndDenormalizeProducts($identifiers)
{
$identifiers = $this->getMainContext()->listToArray($identifiers);
$serializer = $this->getContainer()->get('pim_serializer');
foreach ($identifiers as $identifier) {
$product = $this->getFixturesContext()->getProduct($identifier);
$data = $serializer->normalize($product, 'json');
$values = $data['values'];
foreach ($values as $attributeCode => $valuesData) {
$attribute = $this->getFixturesContext()->getAttribute($attributeCode);
foreach ($valuesData as $valueData) {
$createdValue = $serializer->denormalize($valueData, 'Pim\\Bundle\\CatalogBundle\\Model\\ProductValue', 'json', ['attribute' => $attribute]);
$newData = $serializer->normalize($createdValue, 'json', ['entity' => 'product']);
assertSame($valueData, $newData, sprintf("Product's \"%s\" value for attribute %s in locale %s and scope %s is not correct", $identifier, $attributeCode, $valueData['locale'] ?: 'null', $valueData['scope'] ?: 'null'));
}
}
}
}
示例13: testBelongsToOne
public function testBelongsToOne()
{
$details = new CustomerDetail();
$source = DataSource::make($details);
$source['biography'] = 'A nice life!';
$source['accepts_cookies'] = 0;
$source['customer.name'] = 'Frank';
$source['customer.surname'] = 'Sinatra';
assertSame('A nice life!', $source['biography']);
assertSame(0, $source['accepts_cookies']);
$source->save();
assertSame(1, Customer::all()->count());
assertSame(1, CustomerDetail::all()->count());
// test that we don't create duplicates
$source['biography'] = 'prefers not say';
$source['customer.name'] = 'Frank';
assertSame(1, Customer::all()->count());
assertSame(1, CustomerDetail::all()->count());
}
示例14: compareFile
/**
* @param array $expectedLines
* @param array $actualLines
* @param string $path
*
* @throws \Exception
*/
protected function compareFile(array $expectedLines, array $actualLines, $path)
{
$expectedCount = count($expectedLines);
$actualCount = count($actualLines);
assertSame($expectedCount, $actualCount, sprintf('Expecting to see %d rows, found %d', $expectedCount, $actualCount));
$currentActualLines = current($actualLines);
$currentExpectedLines = current($expectedLines);
$headerDiff = array_diff($currentActualLines, $currentExpectedLines);
if (0 !== count(array_diff($currentActualLines, $currentExpectedLines))) {
throw new \Exception(sprintf("Header in the file %s does not match \n expected one: %s \n missing headers : %s", $path, implode(' | ', current($actualLines)), implode(' | ', $headerDiff)));
}
array_shift($actualLines);
array_shift($expectedLines);
foreach ($expectedLines as $expectedLine) {
$rows = array_filter($actualLines, function ($actualLine) use($expectedLine) {
return 0 === count(array_diff($expectedLine, $actualLine));
});
if (1 !== count($rows)) {
throw new \Exception(sprintf('Could not find a line containing "%s" in %s', implode(' | ', $expectedLine), $path));
}
}
}
示例15: testExistingChildren
public function testExistingChildren()
{
// --- test load
$this->createModels(Customer::class, []);
$this->createModels(Order::class, [['code' => 'a1', 'shipping' => 'home', 'customer_id' => 1], ['code' => 'b1', 'shipping' => 'office', 'customer_id' => 1]]);
$customer = new Customer();
$source = Datasource::make(new Customer());
$source['id'] = 1;
$source['name'] = 'Frank';
$source['surname'] = 'Sinatra';
$source->save();
// this is how eloquent behaves (always false)
assertFalse(isset($customer->orders));
// this is how datasource behaves (always true)
assertTrue(isset($source['orders']));
assertInstanceOf(Collection::class, $customer->orders);
assertInstanceOf(Collection::class, $source['orders']);
assertModelArrayEqual(Order::all(), $source['orders']);
// don't do this at home, folks :)
assertSame('Frank', $source['orders.0.customer.name']);
assertSame('Frank', $source['orders.0.customer.orders.0.customer.name']);
}