Log message #4103558

# At Username Text
# Dec 14th 2017, 11:00 neon1024 You probably meant `$this->request->getParam('prefix') === 'admin'`
# Dec 14th 2017, 10:59 neon1024 I mean, that’s how I do it. Although my check of the prefix is a little more strict
# Dec 14th 2017, 10:59 neon1024 That’s how you do it
# Dec 14th 2017, 10:58 slackebot 'admin') { //$this->layout = 'admin'; $this->viewBuilder()->setLayout('admin'); } ``` any idea ?
# Dec 14th 2017, 10:58 psantos I need to use a differnt layout for all controller in my admin area with admin prefix... so in all controller I am including this: ``` public function beforeFilter(Event $event) { $this->viewBuilder()->setLayout('admin'); } ``` There is no a way to set this on one place only? I tried this in `beforeFilter()` from AppController.php but does not work: ``` if (isset($this->params['prefix']) andand $this->params['prefix'] ==
# Dec 14th 2017, 10:58 neon1024 Especially if you fall into the black hole of trying to mock a table instance, which then mocks the schema which mocks the connection, and down you gooooo
# Dec 14th 2017, 10:57 neon1024 Table method can sometimes be frustrating to test as they often rely on the ORM, which is hard to mock
# Dec 14th 2017, 10:56 neon1024 As you’re not testing the entity
# Dec 14th 2017, 10:56 neon1024 So in your test you use a generic entity mock
# Dec 14th 2017, 10:55 neon1024 Which then abstracts away the concrete class instance
# Dec 14th 2017, 10:55 neon1024 Unless your method requires a specific method in the entity class, you can typehint `EntityInterface`
# Dec 14th 2017, 10:55 neon1024 The D in SOLID
# Dec 14th 2017, 10:53 birdy247 :+1:
# Dec 14th 2017, 10:52 neon1024 Or mock it
# Dec 14th 2017, 10:52 neon1024 Use `new Entity()`
# Dec 14th 2017, 10:52 birdy247 i.e. new PaymentOptions([...
# Dec 14th 2017, 10:52 birdy247 Would it be ok, to use ->get() in my table test to get the entity, or better to setup the entity in the test itself
# Dec 14th 2017, 10:51 birdy247 @neon1024 I am trying to test a Table method. I pass the table method an entity
# Dec 14th 2017, 10:45 birdy247 @neon1024 SOLID advice :)
# Dec 14th 2017, 10:31 neon1024 Follow Chris, https://twitter.com/grmpyprogrammer
# Dec 14th 2017, 10:26 neon1024 That’s the balance
# Dec 14th 2017, 10:26 neon1024 But not pre-optimisation!
# Dec 14th 2017, 10:26 neon1024 Then you start seeing the code smells as you’re creating them, allowing for more pro-active refactoring
# Dec 14th 2017, 10:26 neon1024 Doing some TDD helps. As it makes you focus on creating smaller more concise methods which do simple things well
# Dec 14th 2017, 10:25 neon1024 Unit testing is actually really easy, but the problem is that people write terrible code and then have trouble trying to write tests for it. When in fact if writing the unit test is really hard, it’s indicative of a code smell
# Dec 14th 2017, 10:25 neon1024 It’ll also avoid you drifting into mocking hell, and inadvertently writing integration tests
# Dec 14th 2017, 10:24 neon1024 Making your unit tests easier to write, your system under test smaller, and your tests more predictable
# Dec 14th 2017, 10:24 neon1024 At least then when you come to test, you can easily pass in fixed dependencies
# Dec 14th 2017, 10:23 neon1024 https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
# Dec 14th 2017, 10:23 neon1024 Remember SOLID
# Dec 14th 2017, 10:23 neon1024 Never reach out for dependencies
# Dec 14th 2017, 10:22 birdy247 @neon1024 so pass them in as options rather than looking them up internally
# Dec 14th 2017, 10:18 neon1024 Otherwise you’ll make writing unit tests very hard
# Dec 14th 2017, 10:18 neon1024 If they’re that interdependent then you need to refactor
# Dec 14th 2017, 10:11 birdy247 as Method B relies on Method C and Method D (which I am stubbing)
# Dec 14th 2017, 10:10 birdy247 I am not sure if using too many stubs is considered wrong
# Dec 14th 2017, 10:08 birdy247 @neon1024, I have 1/ unit tested Method B, 2/ unit test Method A with a stub for B
# Dec 14th 2017, 10:07 neon1024 If you’re asking the question, then you already know the answer
# Dec 14th 2017, 10:04 birdy247 ^^ in the context of testing Method A
# Dec 14th 2017, 10:04 birdy247 If I am testing method A, who's outcome is affected by an internal call to Method B, would this be a candidiate for mocking Method B?
# Dec 14th 2017, 09:56 meowcate That means I'll need to do many separated calls to mysql. Maybe there is a better way, just asking.