mercredi 26 septembre 2018

CakePHP 3 + Codeception

I try to use codeception testing framework with cakePHP. I installed this plugin via composer: https://github.com/cakephp/codeception

I was able to run "vendor/bin/codecept bootstrap" and it created all the tests folders and files. After adding a simple Test I try to run "vendor/bin/codecept run" and it starts running my test and then ends up in some Fatal errors looking like this:

vendor/bin/codecept run
Codeception PHP Testing Framework v2.3.9
Powered by PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

App\TestSuite\Codeception.Acceptance Tests (1)  ---------------------------------------------------------------------------
✔ SigninCest: Try to test (0.00s)
---------------------------------------------------------------------------------------------------------------------------
PHP Fatal error:  Uncaught Error: Call to undefined function Cake\TestSuite\Fixture\loadPHPUnitAliases() in /var/www/html/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php:17
Stack trace:
#0 /var/www/html/vendor/composer/ClassLoader.php(444): include()
#1 /var/www/html/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/var/www/html/v...')
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Cake\\TestSuite\\...')
#3 /var/www/html/vendor/cakephp/codeception/src/Helper/FixtureTrait.php(48): spl_autoload_call('Cake\\TestSuite\\...')
#4 /var/www/html/vendor/cakephp/codeception/src/Framework.php(40): Cake\Codeception\Framework->loadFixtureManager()
#5 /var/www/html/vendor/codeception/codeception/src/Codeception/SuiteManager.php(80): Cake\Codeception\Framework->_initialize()
#6 /var/www/html/vendor/codeception/codeception/src/Codeception/Codecept.php(187): Codeception\SuiteManager->initialize()
#7 /var/www/html/vendor/codeception/codeception/src/Codeception/Codecept.php(158): Codeception in /var/www/html/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php on line 17

I use a ddev-docker environment - if this metters...

And this is my composer.json

{
"name": "cakephp/app",
"description": "CakePHP skeleton app",
"homepage": "https://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
    "php": ">=7.0",
    "cakephp/cakephp": "3.6.*",
    "cakephp/migrations": "^2.0.0",
    "cakephp/plugin-installer": "^1.0",
    "josegonzalez/dotenv": "3.*",
    "mobiledetect/mobiledetectlib": "2.*"
},
"require-dev": {
    "cakephp/bake": "^1.1",
    "cakephp/cakephp-codesniffer": "^3.0",
    "cakephp/codeception": "dev-master",
    "cakephp/debug_kit": "^3.15.0",
    "psy/psysh": "@stable"
},
"suggest": {
    "markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
    "dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan compatibility.",
    "phpunit/phpunit": "Allows automated tests to be run without system-wide install."
},
"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
"autoload-dev": {
    "psr-4": {
        "App\\Test\\": "tests/",
        "Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
    }
},
"scripts": {
    "post-install-cmd": "App\\Console\\Installer::postInstall",
    "post-create-project-cmd": "App\\Console\\Installer::postInstall",
    "post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
    "fullcheck": [
        "@test",
        "@cs-check"
    ],
    "cs-check": "phpcs --colors -p --extensions=php,ctp --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
    "cs-fix": "phpcbf --colors --extensions=php,ctp --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
    "test": "phpunit --colors=always"
},
"prefer-stable": true,
"config": {
    "sort-packages": true
}
}

I also run "composer dump-autoload" because I think it has something to do with the autoloading... but without success. Can anyone help with that?

Greetings!

How to verify Image in Coded Ui test?

I am new to coded UI test, Here my Problem is i want to validate Image, Is it possible to validate Images in coded UI or Not ?

here i want to Validate tick mark. i attached Snapshot also.

Could any body help me out from this issue.

TIA--Attached Image

listenglobal renderer event trigger in angular 6 testing script

I want to test my RolesComponent listenGlobal Renderer method. RolesComponent code below.

import { Component, OnInit, Renderer, AfterViewInit } from '@angular/core';
import { Router } from '@angular/router';

import { AhanaService } from '../../services/ahana.service';

@Component({
    selector: 'app-roles',
    template: '<div><button roleId="1">test click</button></div>',
    styleUrls: ['./roles.component.css']
})
export class RolesComponent implements AfterViewInit {

    constructor(public router: Router, private ahanaService: AhanaService, private renderer: Renderer) {}

    ngAfterViewInit(): void {
        this.renderer.listenGlobal('document', 'click', (event) => {
            if (event.target.hasAttribute("roleId")) {
                var roleId = event.target.getAttribute('roleId')
                // console.log('/configuration/update-role/' + roleId)
                this.router.navigate(['/configuration/update-role/' + roleId]);
            }
        });
    }

}

how to convert RolesComponent.spec.ts and ngAfterViewInit(): void { this.renderer.listenGlobal('document', 'click', (event) => { method call.

React - Enzyme test - simulating change return undefined

I'm new in React Enzyme testing. I want to simulate input/change action.

Second test failed although input '#num1' is found:

Expected value to equal: "23"
Received: "undefined"

I tried using 'text()' instead of 'value', then return "".

Also I wrote a test which look for button text and passed return '+'.

When I remove one of two inputs and find 'input', also return 'undefined'.

App.js

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends React.Component{
        constructor(){
            super();
            this.state = {
                number1: 0,
                number2: 0,
                result: 0
            }
        }

        render(){
            return(
            <div>
                <div>
                    <label>Number 1</label>
                    <input id="num1" onInput={this.rememberNumber1.bind(this)} />
                    <br/><br/>
                    <label>Number 2</label>
                    <input id="num2" onInput={this.rememberNumber2.bind(this)} />
                </div>
                <div>
                    <h1>{this.state.number1}+{this.state.number2}={this.state.result}</h1>
                </div>
                <div>
                    <button id="an" onClick={this.sum.bind(this)}>+</button>
                    <button onClick={this.subtract.bind(this)}>-</button>
                    <button onClick={this.multiply.bind(this)}>*</button>
                    <button onClick={this.divide.bind(this)}>:</button>
                </div>
            </div>
            )
        }

        rememberNumber1(e){
            if (e.target.value==""){
                this.setState({
                    number1: 0
                })
            }
            else {
                this.setState({
                    number1: e.target.value
                })
            }
        }

        rememberNumber2(e){
            if (e.target.value==""){
                this.setState({
                    number2: 0
                })
            }
            else {
                this.setState({
                    number2: e.target.value
                })
            }
        }

        sum(e){
            this.setState({
                result: Number(this.state.number1)+Number(this.state.number2)
            })
        }

        subtract(e){
            this.setState({
                result: Number(this.state.number1)-Number(this.state.number2)
            })
        }

        multiply(e){
            this.setState({
                result: Number(this.state.number1)*Number(this.state.number2)
            })
        }

        divide(e){
            this.setState({
                result: Number(this.state.number1)/Number(this.state.number2)
            })
        }
}
export default App;

setupTests.js

import React from 'react';
import { shallow, mount } from 'enzyme';
import App from './App';

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

it('includes input', () => {
    const app = shallow(<App />);
    expect(app.containsMatchingElement(<input/>)).toEqual(true)
});

it('on input', () => {
    const wrapper = mount(<App />);
    wrapper.find('#num1').simulate('change', {target: {value: 23}})
    expect(wrapper.find('#num1').value).toEqual('23')
});

mardi 25 septembre 2018

Attempted polymorphic call of mock types fail in Golang

I have the following mock type, created using Mockery.

type MyController interface{
  Foo(a string, b string) // this is auto-generated
  Bar(a string) // this method is auto-generated
}

type MyMock struct {
    mock.Mock
}

func (m *MyMock) Foo(a string, b string) {
  fmt.Println("MyMock Foo call")
}

func (m *MyMock) Bar(a string) {
  fmt.Println("MyMock Bar call")
}

then I defined a custom mock type:

type CustomMock struct {
  MyMock
  Cache map[string]string
}

so when I define my test suite

type myControllerSuite struct {
   myMock *MyMock
}

func (c *CustomMock) Foo(a string, b string) {
   fmt.Println("Custom Foo call")
}

func (c *CustomMock) Bar(a string) {
  fmt.Println("Custom Bar call")
}

func NewMyControllerSuite(
   myMock *MyMock,
) *myControllerSuite {
  return &myControllerSuite{
    myMock: myMock,
  }
}

and create a new myControllerSuite

customMock := &CustomMock{
  Cache: map[string]string{},
}

When I call the method as shown below:

NewMyControllerSuite(customMock).Foo("a", "b")

Invokes MyMock's Foo() instead of CustomMock, and I get the following error:

assert: mock: I don't know what to return because the method call was unexpected.
    Either do Mock.On("Foo").Return(...) first, or remove the Foo() call.

How can I accomplish the desired result, and call CustomMock's Foo() method instead?

PyTest Allert / Message Box

My code generates an Alert / Message Box using the code below.

import win32api
win32api.MessageBox(0, 'You have reached the end of the data.', 'End of Data')

Is there a way to test that the message appears e.g. something like assert appears? Ideally I'd like to do this using PyTest, however solutions using other frameworks would still be greatly appreciated. It would also be good to test the text within the box e.g. assert message == "You have reached the end of the data."

Basic hapijs/lab test fails asking for a callback argument or return a promise

The very basic test in hapijs/lab fails:

'use strict';
const Code = require('code');
const expect = Code.expect;
const Lab = require('lab');
const lab = exports.lab = Lab.script();

lab.experiment('math', () => {
    lab.test('returns true when 1 + 1 equals 2', () => {
        expect(1 + 1).to.equal(2);
    });
});

with this message:

  1) math returns true when 1 + 1 equals 2:
      Function for "math returns true when 1 + 1 equals 2" should either take a callback argument or return a promise
      at Immediate.setImmediate [as _onImmediate] (/home/ubuntu/projects/service/node_modules/lab/lib/runner.js:755:20)
      at runCallback (timers.js:810:20)
      at tryOnImmediate (timers.js:768:5)
      at processImmediate [as _immediateCallback] (timers.js:745:5)
1 of 1 tests failed
Test duration: 29 ms
Assertions count: 0 (verbosity: 0.00)

The test is straight from Lab documentation. Any idea what is going wrong?