InsertOneFunctionalTest.php 828 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php

namespace MongoDB\Tests\Collection\CrudSpec;

/**
 * CRUD spec functional tests for insertOne().
 *
 * @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
 */
class InsertOneFunctionalTest extends FunctionalTestCase
{
    public function setUp()
    {
        parent::setUp();

        $this->createFixtures(1);
    }

    public function testInsertOneWithANonexistentDocument()
    {
Jeremy Mikola's avatar
Jeremy Mikola committed
21
        $document = ['_id' => 2, 'x' => 22];
22 23 24 25 26

        $result = $this->collection->insertOne($document);
        $this->assertSame(1, $result->getInsertedCount());
        $this->assertSame(2, $result->getInsertedId());

Jeremy Mikola's avatar
Jeremy Mikola committed
27 28 29 30
        $expected = [
            ['_id' => 1, 'x' => 11],
            ['_id' => 2, 'x' => 22],
        ];
31

32
        $this->assertSameDocuments($expected, $this->collection->find());
33 34
    }
}