<?php

namespace Buckhill\Support\tests\units\Noop;

use atoum\test;
use Buckhill\Support\Noop\DotNotation as DotNot;

class DotNotation extends test
{
    public function testDotNotationAccessor()
    {
        $this
            ->given($property = [
                'nested' => [
                    'key' => 'value'
                ],
                'single' => 'level'
            ])
            ->and($model = [
                'nested' => [
                    'model' => [
                        'bool' => true
                    ]
                ],
                'flat' => null
            ])

            ->and($dotnot = new DotNot($property, $model))

            ->then
                ->string($dotnot->dotNotationFromProperty('prop', 'nested.key'))->isEqualTo('value')
                ->variable($dotnot->dotNotationFromProperty('prop', 'flat'))->isNull()
                ->boolean($dotnot->dotNotationFromModel('nested.model.bool'))->isTrue()
                ->variable($dotnot->dotNotationFromModel('flat'))->isNull()
            ;
    }

    public function testDotNotationFromArray()
    {
        $this->given(
            $data = [
                'property' => [
                    'nested' => 'value'
                ]
            ]
        )->and($dotnot = new DotNot())

       ->then
            ->string($dotnot->dotNotationFromArray($data, 'property.nested'))->isEqualTo('value')
            ->array($dotnot->dotNotationFromArray($data, 'property'))->hasSize(1)
            ;
    }

}