Tuesday, April 5, 2016

Codeception - How to read YAML file entries


    It has been almost 2 years since my last post. Lately, I've been occupied with PHP unit, REST and acceptance tests.

   Codeception is a testing framework, built with PHP, that allows developers and QA professionals to create all sorts of tests for their projects. The syntax is almost human readable and clean. The framework itself is configurable and uses YAML syntax files to store parameters. This can be very handy at times, the question is, how to access those values.

   There are 1 core class that can help us with this \Codeception\Configuration and the process is very easy.

    Lets have a look at the following config file called api.suite.yml

class_name: ApiTester
modules:
    enabled:
        - \Helper\Api
        - REST:
                depends: PhpBrowser
                url:  'http://my.local.dev'
                part: Json
testdata:
    api_secret: '87897ddhgg'
    api_key: '7367hcfkdjhfkhfdkhf83787'

This file describes the configuration for the API test suite. Most RESTfull APIs use a key and/or  secret. To be able to use the values, the following lines of code will do the job:


$thisConfig = \Codeception\Configuration::config();
$apiSettings = \Codeception\Configuration::suiteSettings('api', $thisConfig);

$apiSecret = $apiSettings['testdata']['api_secret'];
$apiKey = $apiSettings['testdata']['api_key'];


Now we can use the variables in our tests.

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. عزل فوم بجدة
    الخدمات المقدمة من أفضل شركة عزل فوم بجدة للسادة العملاء
    تعد شركة عزل فوم في جدة من الشركات الرائدة في مجال عوازل الفوم للاسطح والخزانات بمختلف أنواعه والتي تساهم في الحفاظ على أسطح المباني والمنشأت من التعرض لأي من الأضرار .

    وذلك لأن الشركة تعرف جيداً مدى الأضرار الخطيرة الواقعة على العقار جراء التعرض للتغيرات الجوية المختلفة.

    فالعوامل الجوية سواء درجات الحرارة المرتفعة أو هطول الكثير من الأمطار أمر يساعد بالطبع على قصر عمر المبنى الافتراضي.

    لذا تهتم الشركة من خلال خبرائها بتوفير كافة الحلول والأساليب التي تساعد على تطبيق العزل بامتياز بجدية.
    وذلك بالاعتماد على فريق عمل مميز هو الأفضل على مستوى المملكة العربية السعودية في جميع المدن، وكذلك توفير أحدث الأدوات والمعدات المستخدمة في تنفيذ اعمال العزل
    أنواع العزل المستخدمة من قبل الشركة
    1- عزل فوم مائى حراري
    2- عزل بولي يوريثان
    3- عزل فوم شينكو
    4- عزل الفوم الحراري
    أمور يجب الاهتمام بها عند تطبيق العزل
    الحرص على اختيار الموعد المناسب الذي يتم من خلالها القيام بأعمال العزل لضمان نجاحه.
    الانتباه باختيار أفضل المواد الكيميائية والملائمة لنوع حالة السطح والمادة المصنعة.
    ومن أهم الأمور يجب اختيار أفضل شركة عزل فوم بجدة لضمان العمل بجدية كبيرة.
    تعد الشركة من أفضل شركات عزل فوم و التي تم تصنيفها كواحدة من كبرى المؤسسات المتطورة

    ReplyDelete