<commit_before><?php

namespace spec\MageTest\MagentoExtension\Fixture;

use PHPSpec2\Specification;

class Product implements Specification
{
    function described_with()
    {
        \Mage::app();
        $this->productModel = \Mockery::mock(new \Mage_Catalog_Model_Product);

        $productModel = $this->productModel;
        $factory = function () use ($productModel) { return $productModel; };

        $this->product->isAnInstanceOf('MageTest\MagentoExtension\Fixture\Product', array($factory));

        $entityType = \Mockery::mock(new \Mage_Eav_Model_Entity_Type);
        $productResourceModel = \Mockery::mock('Mage_Catalog_Model_Resource_Product');

        $entityType->shouldReceive('getDefaultAttributeSetId')->andReturn(7);
        $productResourceModel->shouldReceive('getEntityType')->andReturn($entityType);
        $this->productModel->shouldReceive('getResource')->andReturn($productResourceModel)->ordered();
    }

    function it_should_create_a_product_given_all_required_attributes()
    {
        $data = array(
            'attribute_set_id' => 7,
            'name' => 'product name',
            'weight' => 2,
            'visibility'=> \Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
            'status' => \Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
            'price' => 100,
            'description' => 'Product description',
            'short_description' => 'Product short description',
            'tax_class_id' => 1,
            'type_id' => \Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
            'stock_data' => array( 'is_in_stock' => 1, 'qty' => 99999 ),
            'sku' => 'sdf'
        );

        $this->productModel->shouldReceive('setData')
            ->with($data)->once()->andReturn($this->productModel)->ordered();
        $this->productModel->shouldReceive('save')->once()->andReturn(true)->ordered();
        $this->productModel->shouldReceive('getIdBySku')->andReturn(false);

        $this->product->create($data);
    }

    function it_should_populate_missing_attributes_when_creating_product()
    {
        $data = array(
            'sku' => 'sku'.time()
        );

        $expected = array(
            'attribute_set_id' => 7,
            'name' => 'product name',
            'weight' => 2,
            'visibility'=> \Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
            'status' => \Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
            'price' => 100,
            'description' => 'Product description',
            'short_description' => 'Product short description',
            'tax_class_id' => 1,
            'type_id' => \Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
            'stock_data' => array( 'is_in_stock' => 1, 'qty' => 99999 ),
            'sku' => $data['sku']
        );

        $this->productModel->shouldReceive('setData')
            ->with($expected)->once()->andReturn($this->productModel)->ordered();
        $this->productModel->shouldReceive('save')->once()->andReturn(true)->ordered();
        $this->productModel->shouldReceive('getIdBySku')->andReturn(false);

        $this->product->create($data);
    }

    function it_should_throw_an_exception_if_creating_with_existing_sku()
    {
        $data = array(
            'sku' => 'sku1'
        );

        $this->productModel->shouldReceive('getIdBySku')->with('sku1')->once()->andReturn(123);

        $this->product->shouldThrow('\Exception', 'SKU provided to product fixture should not be existing')->during('create', array($data));
    }

    function it_should_return_the_created_objects_id()
    {
        $data = array(
            'sku' => 'sku'.time()
        );

        $this->productModel->shouldReceive('setData')->once()->andReturn($this->productModel)->ordered();
        $this->productModel->shouldReceive('save')->once()->andReturn(true)->ordered();
        $this->productModel->shouldReceive('getId')->once()->andReturn(554)->ordered();
        $this->productModel->shouldReceive('getIdBySku')->andReturn(false);

        $this->product->create($data)->shouldBe(554);
    }

    function it_should_load_object_and_delete_it_when_delete_is_requested()
    {
        $this->productModel->shouldReceive('load')->with(554)->once()->andReturn($this->productModel)->ordered();
        $this->productModel->shouldReceive('delete')->once()->andReturn(null)->ordered();

        $this->product->delete(554);
    }
}
<commit_msg>fix spec to mock getId<commit_after><?php

namespace spec\MageTest\MagentoExtension\Fixture;

use PHPSpec2\Specification;

class Product implements Specification
{
    function described_with()
    {
        \Mage::app();
        $this->productModel = \Mockery::mock(new \Mage_Catalog_Model_Product);

        $productModel = $this->productModel;
        $factory = function () use ($productModel) { return $productModel; };

        $this->product->isAnInstanceOf('MageTest\MagentoExtension\Fixture\Product', array($factory));

        $entityType = \Mockery::mock(new \Mage_Eav_Model_Entity_Type);
        $productResourceModel = \Mockery::mock('Mage_Catalog_Model_Resource_Product');

        $entityType->shouldReceive('getDefaultAttributeSetId')->andReturn(7);
        $productResourceModel->shouldReceive('getEntityType')->andReturn($entityType);
        $this->productModel->shouldReceive('getResource')->andReturn($productResourceModel)->ordered();
    }

    function it_should_create_a_product_given_all_required_attributes()
    {
        $data = array(
            'attribute_set_id' => 7,
            'name' => 'product name',
            'weight' => 2,
            'visibility'=> \Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
            'status' => \Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
            'price' => 100,
            'description' => 'Product description',
            'short_description' => 'Product short description',
            'tax_class_id' => 1,
            'type_id' => \Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
            'stock_data' => array( 'is_in_stock' => 1, 'qty' => 99999 ),
            'sku' => 'sdf'
        );

        $this->productModel->shouldReceive('setData')
            ->with($data)->once()->andReturn($this->productModel)->ordered();
        $this->productModel->shouldReceive('save')->once()->andReturn(true)->ordered();
        $this->productModel->shouldReceive('getId')->andReturn(1);
        $this->productModel->shouldReceive('getIdBySku')->andReturn(false);

        $this->product->create($data);
    }

    function it_should_populate_missing_attributes_when_creating_product()
    {
        $data = array(
            'sku' => 'sku'.time()
        );

        $expected = array(
            'attribute_set_id' => 7,
            'name' => 'product name',
            'weight' => 2,
            'visibility'=> \Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
            'status' => \Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
            'price' => 100,
            'description' => 'Product description',
            'short_description' => 'Product short description',
            'tax_class_id' => 1,
            'type_id' => \Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
            'stock_data' => array( 'is_in_stock' => 1, 'qty' => 99999 ),
            'sku' => $data['sku']
        );

        $this->productModel->shouldReceive('setData')
            ->with($expected)->once()->andReturn($this->productModel)->ordered();
        $this->productModel->shouldReceive('save')->once()->andReturn(true)->ordered();
        $this->productModel->shouldReceive('getId')->andReturn(1);
        $this->productModel->shouldReceive('getIdBySku')->andReturn(false);

        $this->product->create($data);
    }

    function it_should_throw_an_exception_if_creating_with_existing_sku()
    {
        $data = array(
            'sku' => 'sku1'
        );

        $this->productModel->shouldReceive('getIdBySku')->with('sku1')->once()->andReturn(123);

        $this->product->shouldThrow('\Exception', 'SKU provided to product fixture should not be existing')->during('create', array($data));
    }

    function it_should_return_the_created_objects_id()
    {
        $data = array(
            'sku' => 'sku'.time()
        );

        $this->productModel->shouldReceive('setData')->once()->andReturn($this->productModel)->ordered();
        $this->productModel->shouldReceive('save')->once()->andReturn(true)->ordered();
        $this->productModel->shouldReceive('getId')->once()->andReturn(554)->ordered();
        $this->productModel->shouldReceive('getIdBySku')->andReturn(false);

        $this->product->create($data)->shouldBe(554);
    }

    function it_should_load_object_and_delete_it_when_delete_is_requested()
    {
        $this->productModel->shouldReceive('load')->with(554)->once()->andReturn($this->productModel)->ordered();
        $this->productModel->shouldReceive('delete')->once()->andReturn(null)->ordered();

        $this->product->delete(554);
    }
}

{'fraction_non_alphanumeric': 0.1649142224681793, 'fraction_numerical': 0.009739900387382401, 'mean_word_length': 3.1506660542030316, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 251, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3948990', 'n_tokens_mistral': 2724, 'n_tokens_neox': 2621, 'n_words': 312}